home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / Actions.py < prev    next >
Encoding:
Text File  |  2000-11-16  |  88.2 KB  |  3,017 lines

  1. import Bladex
  2. ### /    Added by Dario    \ ####
  3. import Ontake
  4. import Stars
  5. import string
  6. ### \   Added by Dario    / ####
  7. import math
  8. import Reference
  9. import Breakings
  10. import InitDataField
  11. import OnInitTake # Added by Manuel
  12. import AuxFuncs #Para Faces de camara
  13. import B3DLib
  14. import netgame
  15. import Damage
  16. import CharStats
  17. import MenuText
  18. import BInput
  19. import Select
  20.  
  21. import Netval
  22. import Torchs
  23. import ItemTypes
  24.  
  25. #
  26. # Fade out values -> For Enric
  27. #
  28. START_FADEOUT_IN_BIG_FALL=2.0
  29. END_FADEOUT_IN_BIG_FALL=2.5
  30.  
  31. if Reference.DEBUG_INFO == 1:
  32.     import pdb
  33. import pdb
  34. TRUE=(1==1)
  35. FALSE=(1!=1)
  36. #
  37. #Values returned by StatR
  38. #Tells what is being carried in the right hand
  39. #
  40. RA_NO_WEAPON=0  #Nothing in hand
  41. RA_1H_WEAPON=1  #Carring 1 hand weapon
  42. RA_BOW=2        #A bow
  43. RA_2H_OBJECT=3  #A 2 hand object
  44. RA_TORCH=4      #NEW : Now the torch is in the right hand!
  45.  
  46. #
  47. #Values returned by StatL
  48. #Tells what is being carried in the left hand
  49. #
  50. LA_NO_WEAPON=0  #Nothing
  51. LA_SHIELD=1     #Shield
  52. LA_BOW=2        #A bow
  53.  
  54. LA_2H_OBJECT=2  #A 2 hand object
  55.  
  56. PI = math.pi
  57. TWOPI = PI*2
  58. FACINGANGLE =  PI * 0.125
  59. BEHINDANGLE =  PI * 0.75
  60.  
  61. B_SOLID_MASK_PERSON     =1
  62. B_SOLID_MASK_FLOOR      =2
  63. B_SOLID_MASK_CAMERA     =4
  64. B_SOLID_MASK_PARTICLES  =8
  65.  
  66. MESSAGE_START_WEAPON         =7
  67. MESSAGE_STOP_WEAPON          =8
  68.  
  69. MESSAGE_START_TRAIL         =14
  70. MESSAGE_STOP_TRAIL          =15
  71.  
  72. # Interpolation Types for DoAction()
  73. InterpWithOff=0,
  74. InterpWithOutOff=1,
  75. InertialIntrp=2,
  76. FixedRFootIntep=3,
  77. FixedLFootIntep=4,
  78. FixedFootAutoInterp=5
  79.  
  80.  
  81. # Table to be used by other libraries
  82. TryToTakeCallBacks = []
  83.  
  84. #
  85. # Message Support Functions
  86. #
  87.  
  88.  
  89. # Message to the user, maybe this should go to the screen
  90. def ReportMsg(Msg):
  91.     if netgame.GetNetState()==0:
  92.         import GameText
  93.         GameText.WriteTextAux(MenuText.GetMenuText(Msg),2.0,255,255,255,[])
  94.  
  95.  
  96. def GetListOfObjectsAt(inv,id):
  97.  
  98.     if inv.GetNumberObjectsAt(id)==1:
  99.         name = inv.GetObject(id)
  100.         if name:
  101.             return [name]
  102.         else:
  103.             return []
  104.     else:
  105.         corray = range(inv.GetNumberObjectsAt(id))
  106.  
  107.     resulto = []
  108.     for i in corray:
  109.         name = inv.GetObject(id)
  110.         if not name:
  111.             return []
  112.         inv.RemoveObject(name)
  113.         ExtendedTakeObject(inv,name)
  114.         resulto.append(name)
  115.     return resulto
  116.  
  117.  
  118. def RemoveAllKeys(EntityName):
  119.     me = Bladex.GetEntity(EntityName)
  120.     inv= me.GetInventory()
  121.     keyNames = []
  122.  
  123.     for j in range(inv.nKeys):
  124.         keyNames.append(inv.GetKey(j))
  125.  
  126.     for key in keyNames:
  127.         inv.RemoveKey(key)
  128.  
  129. def RemoveNoTravelObjects(EntityName):
  130.  
  131.     me        = Bladex.GetEntity(EntityName)
  132.     inv       = me.GetInventory()
  133.     objname   = inv.GetObject(0)
  134.     counterid = 0
  135.  
  136.     while objname:
  137.         obj     = Bladex.GetEntity(objname)
  138.         if obj.Kind in Reference.TravelObjects:
  139.             counterid = counterid + 1
  140.         else:
  141.             inv.RemoveObject(objname)
  142.         objname = inv.GetObject(counterid)
  143.  
  144. #
  145. #
  146. #
  147. def PutAllInBack(EntityName):
  148.     me = Bladex.GetEntity(EntityName)
  149.     right= me.InvRight
  150.     left= me.InvLeft
  151.     rightback= me.InvRightBack
  152.     leftback= me.InvLeftBack
  153.  
  154.  
  155.     inv= me.GetInventory()
  156.     inv.LinkRightHand ("")
  157.     inv.LinkLeftHand ("")
  158.  
  159.     inv.LinkBack("")
  160.  
  161.  
  162.     # Left Back
  163.     if leftback:
  164.         inv.LinkLeftBack(leftback)
  165.     elif not leftback and left:
  166.         inv.LinkLeftBack(left)
  167.     elif leftback and left:
  168.         print "ERROR - Actions.PutAllInBack -> leftback and left both diff on none!!!"
  169.         inv.LinkLeftBack(leftback)
  170.         print "   Linked only the back one..."
  171.  
  172.  
  173.     # Right Back
  174.     if rightback:
  175.         inv.LinkRightBack(rightback)
  176.     elif not rightback and right:
  177.         inv.LinkRightBack(right)
  178.     elif rightback and right:
  179.         print "ERROR - Actions.PutAllInBack -> rightback and right both diff on none!!!"
  180.         inv.LinkRightBack(rightback)
  181.         print "   Linked only the back one..."
  182.  
  183.  
  184.  
  185.  
  186. #
  187. #
  188. #
  189. def Start_Weapon (EntityName,EventName):
  190.     me = Bladex.GetEntity(EntityName)
  191.     if me:
  192.         inv= me.GetInventory()
  193.         if inv:
  194.             weapon_name= inv.GetActiveWeapon()
  195.             if weapon_name:
  196.                 weapon= Bladex.GetEntity(weapon_name)
  197.                 if weapon:
  198.                     #print "Start Weapon"
  199.                     weapon.MessageEvent(Reference.MESSAGE_START_WEAPON,0,0)
  200.  
  201. def Stop_Weapon (EntityName,EventName):
  202.     me = Bladex.GetEntity(EntityName)
  203.     if me:
  204.         inv= me.GetInventory()
  205.         if inv:
  206.             weapon_name= inv.GetActiveWeapon()
  207.             if weapon_name:
  208.                 weapon= Bladex.GetEntity(weapon_name)
  209.                 if weapon:
  210.                     #print "Stop Weapon"
  211.                     weapon.MessageEvent(Reference.MESSAGE_STOP_WEAPON,0,0)
  212.  
  213. def Start_Weapon_Special (EntityName,EventName):
  214.     me = Bladex.GetEntity(EntityName)
  215.     if me:
  216.         inv= me.GetInventory()
  217.         if inv:
  218.             weapon_name= inv.GetActiveWeapon()
  219.             if weapon_name:
  220.                 weapon= Bladex.GetEntity(weapon_name)
  221.                 if weapon:
  222.                     if weapon.Data:
  223.                         try: weapon.Data.Start_Weapon_Special (EntityName,EventName)
  224.                         except AttributeError: pass
  225.  
  226. def Stop_Weapon_Special (EntityName,EventName):
  227.     me = Bladex.GetEntity(EntityName)
  228.     if me:
  229.         inv= me.GetInventory()
  230.         if inv:
  231.             weapon_name= inv.GetActiveWeapon()
  232.             if weapon_name:
  233.                 weapon= Bladex.GetEntity(weapon_name)
  234.                 if weapon:
  235.                     if weapon.Data:
  236.                         try: weapon.Data.Stop_Weapon_Special (EntityName,EventName)
  237.                         except AttributeError: pass
  238.  
  239. def Start_Trail (EntityName,EventName):
  240.     me = Bladex.GetEntity(EntityName)
  241.     if me:
  242.         inv= me.GetInventory()
  243.         if inv:
  244.             weapon_name= inv.GetActiveWeapon()
  245.             if weapon_name:
  246.                 weapon= Bladex.GetEntity(weapon_name)
  247.                 if weapon:
  248.                     weapon.MessageEvent(Reference.MESSAGE_START_TRAIL,0,0)
  249.  
  250. def Stop_Trail (EntityName,EventName):
  251.     me = Bladex.GetEntity(EntityName)
  252.     if me:
  253.         inv= me.GetInventory()
  254.         if inv:
  255.             weapon_name= inv.GetActiveWeapon()
  256.             if weapon_name:
  257.                 weapon= Bladex.GetEntity(weapon_name)
  258.                 if weapon:
  259.                     weapon.MessageEvent(Reference.MESSAGE_STOP_TRAIL,0,0)
  260.  
  261. def GraspString (EntityName,EventName):
  262.     me= Bladex.GetEntity(EntityName)
  263.     if me:
  264.         inv= me.GetInventory()
  265.         if inv:
  266.             if inv.HoldingBow:
  267.                 bow= Bladex.GetEntity(inv.GetBow())
  268.                 try: bow.Data.GraspString()
  269.                 except AttributeError: print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('"+bow.Name+"'))"
  270.  
  271. def UnGraspString (EntityName,EventName):
  272.     me= Bladex.GetEntity(EntityName)
  273.     if me:
  274.         inv= me.GetInventory()
  275.         if inv:
  276.             if inv.HoldingBow:
  277.                 bow= Bladex.GetEntity(inv.GetBow())
  278.                 try: bow.Data.UnGraspString()
  279.                 except AttributeError: print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('"+bow.Name+"'))"
  280.  
  281.  
  282. def AddQuiver(inv, new_quiver_name):
  283.     new_quiver= Bladex.GetEntity(new_quiver_name)
  284.  
  285.     # Do we already have a quiver of this type
  286.     for i in range (inv.nQuivers):
  287.         quiver_name= inv.GetQuiver(i)
  288.         quiver= Bladex.GetEntity(quiver_name)
  289.         if quiver.Data.ArrowType==new_quiver.Data.ArrowType:
  290.             # Select this quiver
  291.             inv.SetCurrentQuiver(quiver_name)
  292.             if inv.HoldingBow:
  293.                 inv.LinkRightBack(quiver_name)
  294.  
  295.             # Add the arrows, and delete the new quiver
  296.             quiver.Data.ReceiveArrows (new_quiver.Data.NumberOfArrows(), inv.Owner)
  297.             new_quiver.SubscribeToList("Pin")
  298.             inv.LinkRightHand("None")
  299.             return
  300.  
  301.     # Else add a new quiver to the inventory and select it
  302.     inv.AddQuiver(new_quiver_name)
  303.     inv.SetCurrentQuiver(new_quiver_name)
  304.     inv.LinkRightHand("None")
  305.     if inv.HoldingBow:
  306.         inv.LinkRightBack(new_quiver_name)
  307.  
  308.  
  309. def ExtendedTakeObject(inv,Object2TakeName):
  310.     global StakObjects
  311.  
  312.     o = Bladex.GetEntity(Object2TakeName)
  313.     if o.Kind in Reference.StackObjects.keys():
  314.         inv.AddObject(Object2TakeName,Reference.StackObjects[o.Kind]-1)
  315.     else:
  316.         inv.AddObject(Object2TakeName,0)
  317.  
  318.  
  319.  
  320. def TakeObject(EntityName,Object2TakeName, force_take=TRUE):
  321.     #print "Take object "+EntityName+", "+Object2TakeName
  322.     me=Bladex.GetEntity(EntityName)
  323.     inv=me.GetInventory()
  324.  
  325.     #if me.Data and me.Data.pickup_entity:
  326.     #    me.Data.pickup_entity=Object2TakeName
  327.     #PickupEventHandler(EntityName,"PickupEvent")
  328.  
  329.     if IsOneTooMany (EntityName, Object2TakeName):
  330.         if force_take:
  331.             DropToMakeRoomFor(EntityName, Object2TakeName)
  332.         else:
  333.             print (EntityName+": Too many objects of this type: "+Object2TakeName)
  334.             return
  335.  
  336.     object_flag=Reference.GiveObjectFlag(Object2TakeName)
  337.     try:
  338.         me.Data.RegisterObjectAsTaken(Object2TakeName)
  339.     except:
  340.         if EntityName=='Player1':
  341.             print Object2TakeName+" not registered as taken, Players Data class not created yet"
  342.  
  343.     if object_flag == Reference.OBJ_ITEM:
  344.         ExtendedTakeObject(inv,Object2TakeName)
  345.     elif object_flag == Reference.OBJ_SHIELD:
  346.         inv.AddShield(Object2TakeName)
  347.         if not me.InvLeftBack and not me.InvRightBack and not me.InvLeft:
  348.             inv.LinkLeftHand(Object2TakeName)
  349.     elif object_flag == Reference.OBJ_WEAPON:
  350.         flag=Reference.GiveWeaponFlag(Object2TakeName)
  351.         inv.AddWeapon(Object2TakeName,flag)
  352.         if me.InvLeftBack=="" and me.InvRightBack=="" and me.InvRight=="":
  353.             inv.LinkRightHand(Object2TakeName)
  354.     elif object_flag == Reference.OBJ_BOW:    #Corregir?
  355.         inv.AddBow(Object2TakeName)
  356.         if not me.InvLeftBack and not me.InvRightBack and not me.InvRight and not me.InvLeft:
  357.             inv.LinkLeftHand(Object2TakeName)
  358.             #inv.LinkRightHand(Object2TakeName) # Esta bien ? Revisar !
  359.     elif object_flag == Reference.OBJ_QUIVER:
  360.         AddQuiver(inv, Object2TakeName)
  361.     elif object_flag == Reference.OBJ_STANDARD:
  362.         if not me.InvLeftBack and not me.InvRightBack and not me.InvRight:
  363.             inv.LinkRightHand(Object2TakeName)
  364.     elif object_flag == Reference.OBJ_KEY:
  365.         inv.AddKey(Object2TakeName)
  366.     elif object_flag == Reference.OBJ_SPECIALKEY:
  367.         inv.AddSpecialKey(Object2TakeName)
  368.     elif object_flag == Reference.OBJ_TABLET:
  369.         inv.AddTablet(Object2TakeName)
  370.     elif object_flag == Reference.OBJ_ARROW:
  371.         pass
  372.     elif object_flag == Reference.OBJ_USEME and EntityName != "Player1" :
  373.         ExtendedTakeObject(inv,Object2TakeName)
  374.     else:
  375.         print "ERROR adding an object to a character !!!"
  376.         print "Not classified properly in Reference.py!!!"
  377.  
  378.  
  379. def StatR(EntityName):
  380.     me=Bladex.GetEntity(EntityName)
  381.     ObjectName=me.InvRight
  382.     if ObjectName=="None" or not ObjectName:
  383.         return RA_NO_WEAPON
  384.  
  385.     object_flag=Reference.GiveObjectFlag(ObjectName)
  386.  
  387.     if object_flag==Reference.OBJ_BOW:
  388.         return RA_BOW
  389.     #elif object_flag==Reference.OBJ_TORCH:
  390.     #    return RA_TORCH
  391.     else:
  392.         return RA_1H_WEAPON
  393.  
  394. def StatL(EntityName):
  395.     me=Bladex.GetEntity(EntityName)
  396.     ObjectName=me.InvLeft
  397.     if ObjectName=="None" or not ObjectName:
  398.         return LA_NO_WEAPON
  399.  
  400.     object_flag=Reference.GiveObjectFlag(ObjectName)
  401.  
  402.     if object_flag==Reference.OBJ_SHIELD:
  403.         return LA_SHIELD
  404.     elif object_flag==Reference.OBJ_BOW:
  405.         return LA_BOW
  406.     else:
  407.         print "ERROR - Invalid object in left hand!!!"
  408.         print "Check it in Reference.py!!!"
  409.         return
  410.  
  411. #
  412. # IsRightHandStandardObject
  413. #
  414. def IsRightHandStandardObject(EntityName):
  415.     me=Bladex.GetEntity(EntityName)
  416.     if not me.InvRight:
  417.         return FALSE
  418.  
  419.     # Get object type
  420.     object_flag= Reference.GiveObjectFlag(me.InvRight)
  421.     return object_flag == Reference.OBJ_STANDARD
  422.  
  423. #
  424. #
  425. #
  426. def IsRightHandWeaponObject(EntityName):
  427.     me=Bladex.GetEntity(EntityName)
  428.     if not me.InvRight:
  429.         return FALSE
  430.  
  431.     # Get object type
  432.     object_flag= Reference.GiveObjectFlag(me.InvRight)
  433.     return object_flag == Reference.OBJ_WEAPON or object_flag == Reference.OBJ_BOW # Do not include bow ?
  434.  
  435.  
  436. #
  437. # IsRightHandAutomaticObject
  438. #
  439. def IsRightHandAutomaticObject(EntityName):
  440.     me=Bladex.GetEntity(EntityName)
  441.     if not me.InvRight:
  442.         return FALSE
  443.  
  444.     # Get object type
  445.     object_flag= Reference.GiveObjectFlag(me.InvRight)
  446.     return object_flag == Reference.OBJ_USEME
  447.  
  448.  
  449. #
  450. # ShieldOnLeft
  451. #
  452. """
  453. def ShieldOnLeft(EntityName):
  454.     me=Bladex.GetEntity(EntityName)
  455.     if not me.InvLeft:
  456.         return FALSE
  457.  
  458.     # Get object type
  459.     object_flag= Reference.GiveObjectFlag(me.InvLeft)
  460.     return object_flag == Reference.OBJ_USEME
  461. """
  462.  
  463. #################
  464. #
  465. #  A C T I O N S
  466. #
  467. #################
  468.  
  469. #
  470. # Turning Actions -> Shoudl NOT be here!
  471. #
  472.  
  473. def IsBehindEntity(MyName, OtherName):
  474.     them=Bladex.GetEntity(OtherName)
  475.     angle1 = them.Angle
  476.     angle2 = B3DLib.GetEntity2EntityAngle (OtherName, MyName)
  477.     return abs (B3DLib.DiffAngle (angle1, angle2))  >=  BEHINDANGLE
  478.  
  479.  
  480. def IsFacingEntity(MyName, OtherName):
  481.     me=Bladex.GetEntity(MyName)
  482.     angle1 = me.Angle
  483.     angle2 = B3DLib.GetEntity2EntityAngle (MyName, OtherName)
  484.     return abs (B3DLib.DiffAngle (angle1, angle2))  <=  FACINGANGLE
  485.  
  486. def IsFacingPos(MyName, x, z):
  487.     me=Bladex.GetEntity(MyName)
  488.     angle1 = me.Angle;
  489.     p1=me.Position
  490.     x = x-p1[0]
  491.     z = z-p1[2]
  492.     angle2 = B3DLib.GetXZAngle (x, 0.0, z)
  493.     return abs (B3DLib.DiffAngle (angle1, angle2))  <=  FACINGANGLE
  494.  
  495. def Turn180(MyName):
  496.     me=Bladex.GetEntity(MyName)
  497.     angle = me.Angle+PI
  498.     if angle >= TWOPI:
  499.         angle = angle - TWOPI
  500.     me.Face(angle)
  501.  
  502. def QuickTurn180(MyName):
  503.     me=Bladex.GetEntity(MyName)
  504.     angle = me.Angle+PI
  505.     if angle >= TWOPI:
  506.         angle = angle - TWOPI
  507.     me.QuickFace(angle)
  508.  
  509. def TurnToFaceEntity(MyName, OtherName):
  510.     me=Bladex.GetEntity(MyName)
  511.     angle = B3DLib.GetEntity2EntityAngle (MyName, OtherName)
  512.     me.Face(angle)
  513.  
  514. def TurnToFaceEntityNow(MyName, OtherName):
  515.     me=Bladex.GetEntity(MyName)
  516.     angle = B3DLib.GetEntity2EntityAngle (MyName, OtherName)
  517.     me.Angle = angle
  518.  
  519. def QuickTurnToFaceEntity(MyName, OtherName):
  520.     me=Bladex.GetEntity(MyName)
  521.     angle = B3DLib.GetEntity2EntityAngle (MyName, OtherName)
  522.     me.QuickFace(angle)
  523.  
  524. def TurnToFacePos(MyName, x, z):
  525.     me=Bladex.GetEntity(MyName)
  526.     p1=me.Position
  527.     x = x-p1[0]
  528.     z = z-p1[2]
  529.     angle = B3DLib.GetXZAngle (x, 0.0, z)
  530.     me.Face(angle)
  531.  
  532. def QuickTurnToFacePos(MyName, x, z):
  533.     me=Bladex.GetEntity(MyName)
  534.     p1=me.Position
  535.     x = x-p1[0]
  536.     z = z-p1[2]
  537.     angle = B3DLib.GetXZAngle (x, 0.0, z)
  538.     me.QuickFace(angle)
  539.  
  540.  
  541.  
  542.  
  543.  
  544. #
  545. # Using Actions
  546. #
  547.  
  548. # Use locations
  549. USE_FROM_INV=0
  550. USE_FROM_NEARBY=2
  551. USE_FROM_TAKE=4
  552.  
  553.  
  554. def StdUse (EntityName):
  555.     me = Bladex.GetEntity(EntityName)
  556.  
  557.     if me.Wuea==Reference.WUEA_ENDED:
  558.         return FALSE
  559.  
  560.     if me.Wuea==Reference.WUEA_WAIT:
  561.         return FALSE
  562.  
  563.  
  564.  
  565.  
  566.     #Para evitar bug de usar un segundo objeto indefinidamente
  567.     if me.AnmEndedFunc:
  568.         return FALSE
  569.  
  570.  
  571.  
  572.     ###Reference.debugprint (EntityName + ": In StdUse")
  573.     TryWithAnother = 1
  574.     if (me.Name[0:6]=="Player") and (me.Data.InventoryActive):
  575.         inv = me.GetInventory()
  576.         object_name = inv.GetSelectedObject()
  577.         if object_name:
  578.             ###Reference.debugprint (EntityName + ": Using "+object_name)
  579.             object = Bladex.GetEntity(object_name)
  580.             if object and object.CanUse:
  581.                 me.Data.obj_used=object
  582.                 InitDataField.Initialise(object)
  583.                 object.Data.UsedBy = EntityName
  584.                 object.UseFunc(object_name, USE_FROM_INV)
  585.                 TryWithAnother = 0
  586.  
  587.  
  588.     if TryWithAnother:
  589.         if me.Data and me.Data.selected_entity:
  590.             if IsValidForUsing (me.Data.selected_entity[0], EntityName):
  591.                 object_flag= Reference.GiveObjectFlag(me.Data.selected_entity[0])
  592.                 if object_flag!=Reference.OBJ_USEME and object_flag!=Reference.OBJ_ITEM:    # Automatics get picked up first
  593.                     object = Bladex.GetEntity(me.Data.selected_entity[0])
  594.                     me.Data.obj_used=object
  595.                     InitDataField.Initialise(object)
  596.                     object.Data.UsedBy = EntityName
  597.                     object.UseFunc(object.Name, USE_FROM_NEARBY)
  598.                     return
  599.  
  600.             if IsValidForTaking (me.Data.selected_entity[0]):
  601.                 me.Data.toggle4t_clearback= FALSE
  602.                 me.Data.stuff_onback_b4= SthOnBack(EntityName)
  603.                 if TryToTake(EntityName, me.Data.selected_entity[0]):
  604.                     return
  605.             else:
  606.                 ReportMsg ("The selected object cannot be taken")
  607.         else:
  608.             ReportMsg ("Nothing selected")
  609.  
  610.  
  611. def IsValidForUsing(instance_name, EntityName):
  612.     me = Bladex.GetEntity(EntityName)
  613.     object = Bladex.GetEntity(instance_name)
  614.  
  615.     if not me or not object or not object.CanUse or not object.UseFunc:
  616.         return FALSE
  617.  
  618.     dist = B3DLib.GetXZDistance (EntityName, instance_name)
  619.     chartype = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  620.  
  621.     # Is it too far?
  622.     if dist > chartype.Reach*1.5:    # Patch because we extend our reach to use (e.g. with a torch)
  623.         return FALSE
  624.  
  625.     # Is it too low?
  626.     heightdiff = -(object.Position[1] - (me.Position[1]+me.Dist2Floor))
  627.     if heightdiff < chartype.MinTake:
  628.         return FALSE
  629.  
  630.     #Is it too high?
  631.     if heightdiff > chartype.MaxTake5:
  632.         return FALSE
  633.  
  634.     return TRUE
  635.  
  636. def has_torch (EntityName):
  637.     me=Bladex.GetEntity (EntityName)
  638.     obj_name = me.InvRight
  639.     if obj_name:
  640.         obj = Bladex.GetEntity(obj_name)
  641.         if obj:
  642.             return obj.Kind == "Antorcha"
  643.     return 0
  644.  
  645.  
  646. def DestroyBurningItem (EntityName, DestroyTime):
  647.     ###Reference.debugprint (EntityName + ": Im being destroyed")
  648.     obj=Bladex.GetEntity(EntityName)
  649.     #obj.SubscribeToList("Pin")
  650.     if obj:
  651.         try:
  652.             if not obj.Data.brkobjdata:
  653.                 Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  654.         except:
  655.             Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  656.  
  657.         ###Reference.debugprint (EntityName + ": Setting Light to pieces with destroy time " + `DestroyTime`)
  658.         brkobj=obj.Data.brkobjdata
  659.         Breakings.ExplodeSpecialObject (EntityName, 3500.0)
  660.  
  661.     # Set light to the pieces
  662.     ###Reference.debugprint (EntityName + ": Setting Light to pieces...")
  663.     for n in brkobj.n_piezas:
  664.         brkobj.pieza[n].CatchOnFire(0.0,0.0,0.0)
  665.  
  666.  
  667.  
  668. def StdSetFireToUseFunc(ObjectName,use_from):
  669.     object=Bladex.GetEntity(ObjectName)
  670.     from_pos = (0.0, 0.0, 0.0)
  671.     if use_from==USE_FROM_INV or use_from==USE_FROM_NEARBY or use_from==USE_FROM_TAKE:
  672.         EntityName = object.Data.UsedBy
  673.         me = Bladex.GetEntity(EntityName)
  674.         if me:
  675.             if not has_torch (EntityName):
  676.                 return
  677.             torch = Bladex.GetEntity(me.InvRight)
  678.             if torch.Data.torchobjdata.LightStatus==Torchs.OFF:
  679.                 return
  680.             object.UseFunc = 0
  681.             object.Data.UsedBy = me.InvRight
  682.             QuickTurnToFaceEntity (EntityName, ObjectName)
  683.             # Launch the set fire to animation depending on the height diff
  684.             heightdiff = -(object.Position[1] - (me.Position[1]+me.Dist2Floor))
  685.             chartype = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  686.  
  687.             me.AddAnmEventFunc("SetAlightEvent",SetAlightEventHandler)
  688.             if heightdiff <= chartype.MaxTake1:
  689.                 me.LaunchAnmType("fire_g")
  690.             elif heightdiff <= chartype.MaxTake2:
  691.                 me.LaunchAnmType("fire0")
  692.             elif heightdiff <= chartype.MaxTake3:
  693.                 me.LaunchAnmType("fire1")
  694.             elif heightdiff <= chartype.MaxTake4:
  695.                 me.LaunchAnmType("fire2")
  696.             elif heightdiff <= chartype.MaxTake5:
  697.                 me.LaunchAnmType("fire3")
  698.  
  699. def SetAlight (ObjectName):
  700.     object = Bladex.GetEntity (ObjectName)
  701.     if object:
  702.         try:
  703.             UserName = object.Data.UsedBy
  704.             user = Bladex.GetEntity(UserName)
  705.             user_pos = user.Position
  706.         except:
  707.             user_pos = (0.0, 0.0, 0.0)
  708.         object.CatchOnFire(user_pos[0], user_pos[1], user_pos[2])
  709.         ###Reference.debugprint("Setting "+ ObjectName +" alight")
  710.         # Set up the destruction of the item
  711.         # after a given amount of time
  712.         if object.Data.BurnTime:
  713.             Bladex.AddScheduledFunc(Bladex.GetTime()+object.Data.BurnTime, DestroyBurningItem,(ObjectName,object.Data.DestroyTime,),"SetAlight"+ObjectName)
  714.  
  715. def SetBurnable (EntityName, BurnTime, DestroyTime):
  716.     object=Bladex.GetEntity(EntityName)
  717.     object.UseFunc = StdSetFireToUseFunc
  718.     InitDataField.Initialise(object)
  719.     object.Data.BurnTime = BurnTime
  720.     object.Data.DestroyTime = DestroyTime
  721.  
  722. def SetAlightEventHandler(EntityName, EventName):
  723.     me = Bladex.GetEntity(EntityName)
  724.     me.DelAnmEventFunc(EventName)
  725.     ###Reference.debugprint(EntityName+": in SetAlightEventHandler")
  726.     # Check valid event type
  727.     if EventName != "SetAlightEvent":
  728.         ###Reference.debugprint(EntityName+":-( SetAlightEventHandler has unhandled event")
  729.         return
  730.  
  731.     object = me.Data.obj_used
  732.     if object:
  733.         SetAlight(object.Name)
  734.  
  735.  
  736. # Taking Actions
  737. #
  738.  
  739. """
  740.         Valid Object Checks
  741.  
  742. """
  743. def IsValidForTaking(instance_name):
  744.     object = Bladex.GetEntity(instance_name)
  745.     if(object):
  746.         if object.Static or (object.Weapon and object.WeaponMode==Reference.ACTIVE_WEAPON_MODE):
  747.             ###Reference.debugprint(instance_name+" is static and cannot be taken")
  748.             return FALSE
  749.         if object.Parent:
  750.             parent=Bladex.GetEntity(object.Parent)
  751.             if parent and parent.Person:
  752.                 return FALSE
  753.  
  754.         object_data = None
  755.         if Reference.EntitiesObjectData.has_key(instance_name):
  756.             object_data = Reference.EntitiesObjectData[instance_name]
  757.         elif Reference.DefaultObjectData.has_key(object.Kind):
  758.             object_data = Reference.DefaultObjectData[object.Kind]
  759.         if not object_data:
  760.             ###Reference.debugprint ("The object " + instance_name + " of type " + object.Kind + " is not referenced in any dictionary.")
  761.             return FALSE
  762.         # if its an automatic, and does't have a use func
  763.         if object_data[0] == Reference.OBJ_USEME and not object.CanUse:
  764.             ###Reference.debugprint ("The object " + instance_name + " cannot be used.")
  765.             return FALSE
  766.  
  767.     return TRUE
  768.  
  769. def IsValidForThrowing(object_name):
  770.     object = Bladex.GetEntity(object_name)
  771.     if(object):
  772.         # Get object type
  773.         if Reference.EntitiesObjectData.has_key(object_name):
  774.             object_data = Reference.EntitiesObjectData[object_name]
  775.         elif Reference.DefaultObjectData.has_key(object.Kind):
  776.             object_data = Reference.DefaultObjectData[object.Kind]
  777.         else:
  778.             return FALSE
  779.         object_flag = object_data[0]
  780.         if object_flag == Reference.OBJ_WEAPON or object_flag == Reference.OBJ_BOW or object_flag == Reference.OBJ_STANDARD:
  781.             return TRUE
  782.     return FALSE
  783.  
  784. def IsValidForDropping(ObjectName):
  785.     if Reference.EntitiesObjectData.has_key(ObjectName):
  786.         object_data = Reference.EntitiesObjectData[ObjectName]
  787.     else:
  788.         object = Bladex.GetEntity(ObjectName)
  789.         if not Reference.DefaultObjectData.has_key(object.Kind):
  790.             return TRUE
  791.         object_data = Reference.DefaultObjectData[object.Kind]
  792.  
  793.     object_flag = object_data[0]
  794.  
  795.     # Should check against our drop tables, when they are created
  796.     if object_flag == Reference.OBJ_KEY:
  797.         return FALSE
  798.     elif object_flag == Reference.OBJ_SPECIALKEY:
  799.         return FALSE
  800.     elif object_flag == Reference.OBJ_TABLET:
  801.         return FALSE
  802.     elif object_flag == Reference.OBJ_ITEM:
  803.         return FALSE
  804.     else:
  805.         return TRUE
  806.  
  807. def GetCheckSelected (func, Data):
  808.     if Data:
  809.         if Data.selected_entity:
  810.             s = Data.selected_entity[0]
  811.             if func(s):
  812.                 return s
  813.     return None
  814.  
  815. def DropToMakeRoomFor (EntityName, ObjectName):
  816.     me = Bladex.GetEntity(EntityName)
  817.  
  818.     # Get object type
  819.     object_flag=Reference.GiveObjectFlag(ObjectName)
  820.     inv = me.GetInventory()
  821.  
  822.     # parse the object flag
  823.     DropObjectName= None
  824.     if object_flag == Reference.OBJ_ARMOUR:
  825.         print "Warning DropToMakeRoomFor() unimplimented for Armour..."
  826.     elif object_flag == Reference.OBJ_ITEM:
  827.         ObjectKind =  Bladex.GetEntity(ObjectName).Kind
  828.         for i in range(inv.nObjects):
  829.             auxname = inv.GetObject(i)
  830.             if auxname:
  831.                 if Bladex.GetEntity(auxname).Kind == ObjectKind:
  832.                     DropObjectName= auxname
  833.                     break
  834.             else: break
  835.     elif object_flag == Reference.OBJ_SHIELD:
  836.         DropObjectName= inv.GetShield(0)
  837.     elif object_flag == Reference.OBJ_WEAPON:
  838.         DropObjectName= inv.GetWeapon(0)
  839.     elif object_flag == Reference.OBJ_BOW:
  840.         if inv.HasBow:
  841.             DropObjectName= inv.GetBow()
  842.         else:
  843.             DropObjectName= inv.GetWeapon(0)
  844.     elif object_flag == Reference.OBJ_QUIVER:
  845.         DropObjectName= inv.GetQuiver(0)
  846.     elif object_flag == Reference.OBJ_STANDARD:
  847.         DropObjectName= me.InvRight
  848.     elif object_flag == Reference.OBJ_KEY:
  849.         print "Warning DropToMakeRoomFor() unimplimented for Keys..."
  850.     elif object_flag == Reference.OBJ_SPECIALKEY:
  851.         print "Warning DropToMakeRoomFor() unimplimented for Special Keys..."
  852.     elif object_flag == Reference.OBJ_TABLET:
  853.         print "Warning DropToMakeRoomFor() unimplimented for Tablets..."
  854.     elif object_flag == Reference.OBJ_USEME:
  855.         DropObjectName= me.InvRight
  856.     elif object_flag == Reference.OBJ_ARROW:
  857.         print "Warning DropToMakeRoomFor() unimplimented for Arrows..."
  858.  
  859.     if DropObjectName:
  860.         object= Bladex.GetEntity(DropObjectName)
  861.         if object:
  862.             RemoveFromInventory (me, object, "DropToMakeRoomFor "+ObjectName)
  863.             object.Position= me.Position
  864.             object.ExcludeHitFor(me)
  865.             if object.TestHit:
  866.                 object.RemoveFromWorld()
  867.             else:
  868.                 object.Alpha= 1.0
  869.                 object.Impulse(0.0, 0.0, 0.0)
  870.  
  871. # Do we have all that we can carry of an object type
  872. def IsOneTooMany (EntityName, ObjectName):
  873.     me = Bladex.GetEntity(EntityName)
  874.  
  875.     # Get object type
  876.     if Reference.EntitiesObjectData.has_key(ObjectName):
  877.         object_data = Reference.EntitiesObjectData[ObjectName]
  878.     else:
  879.         object = Bladex.GetEntity(ObjectName)
  880.         object_data = Reference.DefaultObjectData[object.Kind]
  881.  
  882.     object_flag = object_data[0]
  883.  
  884.     ret_val=FALSE
  885.  
  886.     inv = me.GetInventory()
  887.     #if object_flag == Reference.OBJ_ARMOUR:
  888.     #    if me.CharTypeExt<>object_data[1]:
  889.     #        ReportMsg ("Type of armour not for me")
  890.     #        return TRUE
  891.     #    if me.Data.armour_level>=object_data[2]:
  892.     #        ReportMsg ("Quality of armour not worthy")
  893.     #        return TRUE
  894.     #    return FALSE
  895.     #else:
  896.     if object_flag == Reference.OBJ_ITEM:
  897.         ret_val =  inv.nObjects >= inv.maxObjects
  898.         if not ret_val:
  899.             ObjectEntity =  Bladex.GetEntity(ObjectName)
  900.             for i in range(inv.nObjects):
  901.                 auxname = inv.GetObject(i)
  902.                 if auxname:
  903.                     if Bladex.GetEntity(auxname).Kind == ObjectEntity.Kind:
  904.                         ret_val =  inv.GetMaxNumberObjectsAt(i)<=inv.GetNumberObjectsAt(i)
  905.                         break
  906.                 else:
  907.                     break
  908.     elif object_flag == Reference.OBJ_SHIELD:
  909.         ret_val = inv.nShields >= inv.maxShields
  910.     elif object_flag == Reference.OBJ_WEAPON:
  911.         ret_val = inv.nWeapons >= inv.maxWeapons
  912.     elif object_flag == Reference.OBJ_BOW: #Corregir?
  913.         ret_val = inv.nWeapons >= inv.maxWeapons or inv.HasBow
  914.     elif object_flag == Reference.OBJ_QUIVER:
  915.         ret_val = inv.nObjects >= inv.maxObjects
  916.     elif object_flag == Reference.OBJ_STANDARD:
  917.         #if me.InvRight and SthOnBack(EntityName):    # Check right hand is holding
  918.         #    return TRUE
  919.         #else:
  920.         ret_val = FALSE
  921.     elif object_flag == Reference.OBJ_KEY:
  922.         ret_val = FALSE
  923.         #return me.InvRight    # Check right hand is holding
  924.     elif object_flag == Reference.OBJ_SPECIALKEY:
  925.         ret_val = FALSE
  926.     elif object_flag == Reference.OBJ_TABLET:
  927.         ret_val = FALSE
  928.         #return me.InvRight    # Check right hand is holding
  929.     elif object_flag == Reference.OBJ_USEME:
  930.         ret_val = FALSE
  931.         #return me.InvRight     # Check right hand is holding
  932.     elif object_flag == Reference.OBJ_ARROW:
  933.         # Check if we have a full quiver of these already
  934.         # Do we have a quiver
  935.         ret_val= not CouldSheatheArrow(inv, ObjectName)
  936.  
  937.     return ret_val
  938.  
  939.  
  940. def TryToTake(EntityName, ObjectName):
  941.     global TryToTakeCallBacks
  942.  
  943.     me = Bladex.GetEntity(EntityName)
  944.  
  945.     if me.Wuea==Reference.WUEA_ENDED:
  946.         return FALSE
  947.     if me.Wuea==Reference.WUEA_WAIT:
  948.         return FALSE
  949.  
  950.  
  951.     #Para evitar bug de coger un segundo objeto indegfinidamente
  952.     if me.AnmEndedFunc:
  953.         return FALSE
  954.  
  955.     inv=me.GetInventory()
  956.     if inv.CarringObject(ObjectName):
  957.         return FALSE
  958.  
  959.     object = Bladex.GetEntity(ObjectName)
  960.     dist = B3DLib.GetXZDistance (EntityName, ObjectName)
  961.     chartype = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  962.  
  963.     # Is it too far?
  964.     if dist > chartype.Reach:
  965.         ReportMsg ("Not in reach")
  966.         return FALSE
  967.  
  968.     # Is it too low?
  969.     me.Data.last_heightdiff= -(object.Position[1] - (me.Position[1]+me.Dist2Floor))
  970.     ###Reference.debugprint ("START TAKE:  ObjPos: " + `object.Position[1]` + ", MyHeight: "+`me.Position[1]` + ", Dist2Floor: "+`me.Dist2Floor`+", HeightDiff = "+`me.Data.last_heightdiff`)
  971.     ###Reference.debugprint ("MinTake: "+`chartype.MinTake`+ ", MaxTake1: "+`chartype.MaxTake1`+ ", MaxTake2: "+`chartype.MaxTake2`+ ", MaxTake3: "+`chartype.MaxTake3`+ ", MaxTake4: "+`chartype.MaxTake4`+ ", MaxTake5: "+`chartype.MaxTake5`)
  972.     if me.Data.last_heightdiff < chartype.MinTake:
  973.         #pdb.set_trace()
  974.         ReportMsg ("Too low to pick up")
  975.         return FALSE
  976.  
  977.     # Is it too high?
  978.     elif me.Data.last_heightdiff > chartype.MaxTake5:
  979.         ReportMsg ("Too high to pick up")
  980.         return FALSE
  981.  
  982.     # Do I have too many
  983.     elif IsOneTooMany (EntityName, ObjectName):
  984.         ReportMsg ("Too many objects of this type")
  985.         return FALSE
  986.  
  987.     # If someone have something to say, speak now or keep silence forever!
  988.     for f in TryToTakeCallBacks:
  989.         if not f(me, object):
  990.             return FALSE
  991.  
  992.     ###Reference.debugprint(EntityName+": Im Taking"+ObjectName)
  993.     QuickTurnToFaceEntity (EntityName, ObjectName)
  994.     # Store the name of this for the PickupEvent
  995.     me.Data.pickup_entity = ObjectName
  996.  
  997.     IntermediateTake(EntityName,ObjectName)
  998.  
  999.     return TRUE
  1000.  
  1001.  
  1002.  
  1003. def UnSheatheArrow(inv):
  1004.     des_quiver_name=inv.GetSelectedQuiver()
  1005.     inv.LinkRightHand("None")
  1006.     if des_quiver_name:
  1007.         inv.SetCurrentQuiver(des_quiver_name)
  1008.         inv.LinkRightBack("None")
  1009.         inv.LinkRightBack(des_quiver_name)
  1010.         quiver= Bladex.GetEntity(des_quiver_name)
  1011.         if quiver and quiver.Data.NumberOfArrows() > 0:
  1012.             arrow= quiver.Data.GiveArrow ()
  1013.             if arrow:
  1014.                 inv.LinkRightHand(arrow.Name)
  1015.                 return
  1016.     ReportMsg ("Out of Arrows")
  1017.  
  1018. def CouldSheatheArrow(inv, ArrowName):
  1019.     arrow=Bladex.GetEntity(ArrowName)
  1020.     for i in range (inv.nQuivers):
  1021.         quiver_name= inv.GetQuiver(i)
  1022.         quiver= Bladex.GetEntity(quiver_name)
  1023.         if quiver.Data.ArrowType==arrow.Kind:
  1024.             return quiver.Data.NumberOfArrows() < quiver.Data.MaxArrows
  1025.  
  1026.     # If we get this far, a quiver of the correct type was not encountered, so we could create one
  1027.     return TRUE
  1028.  
  1029. def SheatheArrow(inv, ArrowName):
  1030.     UnGraspString (inv.Owner,"UnGraspString")
  1031.     arrow=Bladex.GetEntity(ArrowName)
  1032.     for i in range (inv.nQuivers):
  1033.         quiver_name= inv.GetQuiver(i)
  1034.         quiver= Bladex.GetEntity(quiver_name)
  1035.         if quiver.Data.ArrowType==arrow.Kind:
  1036.             # Select this quiver
  1037.             inv.SetCurrentQuiver(quiver_name)
  1038.             if inv.HoldingBow:
  1039.                 inv.LinkRightBack("None")
  1040.                 inv.LinkRightBack(quiver_name)
  1041.             if quiver.Data.ReceiveArrow (arrow, inv.Owner):
  1042.                 inv.LinkRightHand("None")
  1043.             else:
  1044.                 # We have found a quiver of the correct type,
  1045.                 # but it is probably full.  Just drop the arrow
  1046.                 DropReleaseEventHandler(inv.Owner, "DropRightEvent", FALSE)
  1047.             return
  1048.  
  1049.     # If we get this far, a quiver of the correct type was not encountered, so we create one
  1050.     new_quiver_type= Reference.GiveQuiverType(arrow.Kind)
  1051.     if new_quiver_type:
  1052.         new_quiver= Bladex.CreateEntity(new_quiver_type+"_for_"+inv.Owner, new_quiver_type+'_E', 0,0,0, "Physic")
  1053.         ItemTypes.ItemDefaultFuncs (new_quiver)
  1054.         inv.AddQuiver(new_quiver.Name)
  1055.         inv.SetCurrentQuiver(new_quiver.Name)
  1056.         if inv.HoldingBow:
  1057.             inv.LinkRightBack(new_quiver.Name)
  1058.         new_quiver.Data.SetNumberOfArrows(0, inv.Owner)
  1059.         if new_quiver.Data.ReceiveArrow (arrow, inv.Owner):
  1060.             inv.LinkRightHand("None")
  1061.             return
  1062.  
  1063.     # If we get this far, a quiver of the correct type could not be created
  1064.     DropReleaseEventHandler(inv.Owner, "DropRightEvent", FALSE)
  1065.  
  1066.  
  1067. def Toggle4TakingEvent(pj_name,event):
  1068.     me=Bladex.GetEntity(pj_name)
  1069.     inv=me.GetInventory()
  1070.     me.DelAnmEventFunc(event)
  1071.  
  1072.     # If we're carrying an arrow in the right hand then we can put it back in the quiver
  1073.     if inv.HoldingBow:
  1074.         if me.InvRight:
  1075.             if Reference.GiveObjectFlag(me.InvRight)==Reference.OBJ_ARROW:
  1076.                 SheatheArrow(inv, me.InvRight)    # We must be carrying an arrow in the right hand, lets sheathe it
  1077.         else:
  1078.             # Take an arrow
  1079.             UnSheatheArrow(inv)
  1080.     elif me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack)<>Reference.OBJ_QUIVER:
  1081.         #Pasar lo de right en espada a mano dch
  1082.         if (not me.Data.stuff_onback_b4) and me.Data.toggle4t_clearback:
  1083.             tmpr_back=me.InvRightBack
  1084.             inv.LinkRightBack("None")
  1085.             inv.LinkRightHand(tmpr_back)
  1086.         else:
  1087.             inv.LinkRightHand("None")
  1088.     else:
  1089.         if me.InvRight and (not me.Data.toggle4t_clearback):
  1090.             inv.LinkRightBack(me.InvRight)
  1091.         inv.LinkRightHand("None")
  1092.  
  1093.     if me.Data.toggle4t_clearback:
  1094.         me.Data.toggle4t_clearback= FALSE
  1095.         if me.InvLeftBack and Reference.GiveObjectFlag(me.InvLeftBack)==Reference.OBJ_BOW:
  1096.             ToggleWEvent(pj_name,event)
  1097.  
  1098. def ToggleRight4Taking(EntityName):
  1099.     me=Bladex.GetEntity(EntityName)
  1100.  
  1101.     if IsRightHandStandardObject(EntityName):
  1102.         if TryDropRight(EntityName):
  1103.             print "TryDropRight is ok"
  1104.             DropReleaseEventHandler(EntityName, "DropRightEvent")
  1105.             if me.InvRight:
  1106.                 #print "Still stuff on riht!!!"
  1107.                 return FALSE
  1108.         me.Wuea=Reference.WUEA_ENDED
  1109.  
  1110.  
  1111.     if me.InvRight:
  1112.         #if Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW or (me.InvLeftBack and Reference.GiveObjectFlag(me.InvLeftBack)==Reference.OBJ_BOW):
  1113.         #    me.AddAnmEventFunc("ChangeRLEvent",Toggle4TakingEvent)
  1114.         #    me.LaunchAnmType("Chg_r_l")
  1115.         #else:
  1116.         me.AddAnmEventFunc("ChangeREvent",Toggle4TakingEvent)
  1117.  
  1118.         UnGraspString (EntityName,"UnGraspString")
  1119.         me.LaunchAnmType("Chg_r")
  1120.  
  1121.     return TRUE
  1122.  
  1123.  
  1124. def IntermediateTake(EntityName,ObjectName):
  1125.     me = Bladex.GetEntity(EntityName)
  1126.     object = Bladex.GetEntity(ObjectName)
  1127.  
  1128.     inv=me.GetInventory()
  1129.     if inv.CarringObject(ObjectName):
  1130.         return
  1131.  
  1132.     if inv.HoldingBow: UnGraspString(EntityName, "UnGraspString")
  1133.     # Get object type
  1134.     if Reference.EntitiesObjectData.has_key(ObjectName):
  1135.         object_data = Reference.EntitiesObjectData[ObjectName]
  1136.     else:
  1137.         object_data = Reference.DefaultObjectData[object.Kind]
  1138.     object_flag = object_data[0]
  1139.  
  1140.     if object_flag==Reference.OBJ_ARMOUR:
  1141.  
  1142.         if me.CharTypeExt<>object_data[1]:
  1143.             ReportMsg ("Type of armour not for me")
  1144.             print "Info is " + str(object_data[1])
  1145.             return
  1146.         if me.Data.armour_level>=object_data[2]:
  1147.             ReportMsg ("Quality of armour not worthy")
  1148.             return
  1149.  
  1150.         if (FreeBothHands(EntityName,None,(),0)):
  1151.             TakeMainAnm(EntityName)
  1152.         else:
  1153.             me.AnmEndedFunc=TakeMainAnm
  1154.  
  1155.     #Do we have sthing on the hands?
  1156.     if object_flag==Reference.OBJ_SHIELD:
  1157.         ###Reference.debugprint("Taking a shield...")
  1158.         if me.InvRight:
  1159.             if ToggleRight4Taking(EntityName)==FALSE:
  1160.                 return
  1161.             me.AnmEndedFunc=TakeMainAnm
  1162.         else:
  1163.             TakeMainAnm(EntityName)
  1164.     elif object_flag==Reference.OBJ_BOW:
  1165.         ###Reference.debugprint("Taking a bow...")
  1166.         if me.InvRight:
  1167.             if ToggleRight4Taking(EntityName)==FALSE:
  1168.                 return
  1169.             me.AnmEndedFunc=TakeMainAnm
  1170.         else:
  1171.             TakeMainAnm(EntityName)
  1172.  
  1173.     elif object_flag==Reference.OBJ_WEAPON:
  1174.         ###Reference.debugprint("Taking a weapon ...")
  1175.         if me.InvRight:
  1176.             if ToggleRight4Taking(EntityName)==FALSE:
  1177.                 return
  1178.             me.AnmEndedFunc=TakeMainAnm
  1179.         else:
  1180.             #Are taking a 2h W and do we have a shield? Store shield if so
  1181.             w_flag=Reference.GiveWeaponFlag(ObjectName)
  1182.             if me.InvLeft<>"" and w_flag<>Reference.W_FLAG_1H:
  1183.                 me.AddAnmEventFunc("ChangeLEvent",Left2InvEvent)
  1184.                 me.LaunchAnmType("Chg_l")
  1185.                 me.AnmEndedFunc=TakeMainAnm
  1186.             else:
  1187.                 TakeMainAnm(EntityName)
  1188.     elif object_flag==Reference.OBJ_STANDARD:
  1189.         ###Reference.debugprint("Taking a standard object ...")
  1190.         if inv.HoldingBow:
  1191.             # We have a problem here because the standard object cannot
  1192.             # be used with the bow, and it cannot be put into the inventory.
  1193.             # The solution is to link the bow to the back
  1194.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight)==Reference.OBJ_ARROW:
  1195.                 SheatheArrow(inv, me.InvRight)
  1196.             inv.LinkLeftBack(me.InvLeft)
  1197.             inv.LinkLeftHand("None")
  1198.  
  1199.         if me.InvRight:
  1200.             if ToggleRight4Taking(EntityName)==FALSE:
  1201.                 return
  1202.             me.AnmEndedFunc=TakeMainAnm
  1203.         else:
  1204.             TakeMainAnm(EntityName)
  1205.     else:
  1206.         ###Reference.debugprint("Taking sthing thast is NOT shield/weapon/standard ...")
  1207.         if me.InvRight:
  1208.             if ToggleRight4Taking(EntityName)!=FALSE:
  1209.                 me.AnmEndedFunc=TakeMainAnm
  1210.         else:
  1211.             TakeMainAnm(EntityName)
  1212.  
  1213.  
  1214. def ToggleAfterTakeObj(EntityName):
  1215.     me = Bladex.GetEntity(EntityName)
  1216.     me.AnmEndedFunc=None
  1217.     ###Reference.debugprint("Im in ToggleAfterTakeObj")
  1218.  
  1219.     inv = me.GetInventory()
  1220.  
  1221.     if IsRightHandStandardObject(EntityName):
  1222.         return
  1223.  
  1224.     me.Data.toggle4t_clearback= TRUE
  1225.     if me.Data.stuff_onback_b4:
  1226.         ###Reference.debugprint ("SthingOnBack b4 taking - End")
  1227.         if SthOnBack(EntityName):
  1228.             ToggleRight4Taking(EntityName)
  1229.         else:
  1230.             ToggleRight4Taking(EntityName)
  1231.     else:
  1232.         ###Reference.debugprint ("NOthingOnBack b4 taking - End")
  1233.         ToggleRight4Taking(EntityName)
  1234.  
  1235. #
  1236. # Consulta
  1237. #
  1238. def TakeObject2Inv(EntityName):
  1239.     me = Bladex.GetEntity(EntityName)
  1240.  
  1241.     if not me.Data or not me.Data.pickup_entity:
  1242.         return FALSE
  1243.  
  1244.     object_flag= Reference.GiveObjectFlag(me.Data.pickup_entity)
  1245.  
  1246.     if object_flag==Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW:
  1247.         return FALSE
  1248.  
  1249.     back_flag=SthOnBack(EntityName)
  1250.     if back_flag and object_flag==Reference.OBJ_WEAPON:
  1251.         w_flag=Reference.GiveWeaponFlag(me.Data.pickup_entity)
  1252.         if w_flag<>Reference.W_FLAG_1H:
  1253.             back_flag=0
  1254.  
  1255.     weapon_stay=0
  1256.     if (not me.Data.stuff_onback_b4) and (not back_flag) and (object_flag == Reference.OBJ_WEAPON):
  1257.         if not me.InvLeft or Reference.GiveObjectFlag(me.InvLeft)!=Reference.OBJ_BOW:
  1258.             weapon_stay=1
  1259.     if object_flag <> Reference.OBJ_STANDARD and object_flag <> Reference.OBJ_USEME and (not weapon_stay):
  1260.         return TRUE
  1261.     return FALSE
  1262.  
  1263. def TakeObject2Left(EntityName):
  1264.     me = Bladex.GetEntity(EntityName)
  1265.  
  1266.     #
  1267.     # Not sure , but with the following the error of trying to take a weapon and WHEN TAKING , pressing the key to
  1268.     #take a shield , leaving the weapon on the LEFT hand ( and not taking the shield ) , , dissaers ( more or less )
  1269.     #
  1270.     if me.Data and not (me.Data.pickup_entity==me.InvRight):
  1271.         #print "    ERROR INVENT!!!!"
  1272.         #print "    pickup_entity is " + me.Data.pickup_entity
  1273.         if me.InvRight:
  1274.             #print "    Right was" + me.InvRight
  1275.             return FALSE
  1276.  
  1277.  
  1278.  
  1279.     if me.Data and me.Data.pickup_entity:
  1280.         if not me.InvLeft:
  1281.             object_flag= Reference.GiveObjectFlag(me.Data.pickup_entity)
  1282.             if object_flag==Reference.OBJ_SHIELD:
  1283.                 #DO not left it in left hand if on back a 2hWeapon before taking it!
  1284.                 #if me.Data.stuff_onback_b4==0 and TwoHandedWeaponOnBack(EntityName):
  1285.                 if TwoHandedWeaponOnBack(EntityName):
  1286.                     return FALSE
  1287.                 if not me.InvLeftBack:
  1288.                     return TRUE
  1289.             if object_flag==Reference.OBJ_BOW:
  1290.                 # the bow requires both hands to be free
  1291.                 if not me.InvLeftBack and not me.InvRightBack:
  1292.                     return TRUE
  1293.     return FALSE
  1294.  
  1295. def RemoveRightHandler(EntityName, EventName):
  1296.     me = Bladex.GetEntity(EntityName)
  1297.  
  1298.     me.DelAnmEventFunc(EventName)
  1299.     inv=me.GetInventory()
  1300.     if me.InvRight and Reference.GiveObjectFlag(me.InvRight)==Reference.OBJ_ARROW:
  1301.         SheatheArrow(inv, me.InvRight)
  1302.     else:
  1303.         object_name= me.InvRight
  1304.         inv.LinkRightHand("None")
  1305.         try:
  1306.             if object_name and me.Data.obj2left:
  1307.                 inv.LinkLeftHand(object_name)
  1308.             me.Data.obj2left= None
  1309.         except AttributeError:
  1310.             pass
  1311.  
  1312.  
  1313.  
  1314. def TakeArmour(EntityName):
  1315.     me = Bladex.GetEntity(EntityName)
  1316.  
  1317.     ObjectName=me.Data.pickup_entity
  1318.     object=Bladex.GetEntity(ObjectName)
  1319.  
  1320.     # Get object type
  1321.     if Reference.EntitiesObjectData.has_key(ObjectName):
  1322.         object_data = Reference.EntitiesObjectData[ObjectName]
  1323.     else:
  1324.         object_data = Reference.DefaultObjectData[object.Kind]
  1325.  
  1326.     if object_data[0]<>Reference.OBJ_ARMOUR:
  1327.         print "ERROR in Actions.TakeArmour , object is not an armour!!!"
  1328.         return
  1329.  
  1330.     ct = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  1331.  
  1332.     sound=Bladex.CreateSound("..\\..\\Sounds\\cambio-armadura2.wav",EntityName+"SoundNewArmour")
  1333.     sound.Volume=0.6
  1334.     sound.MinDistance=10000
  1335.     sound.MaxDistance=20000
  1336.     sound.PlayStereo()
  1337.  
  1338.     right= me.InvRight
  1339.     left= me.InvLeft
  1340.     rightback= me.InvRightBack
  1341.     leftback= me.InvLeftBack
  1342.  
  1343.  
  1344.     inv= me.GetInventory()
  1345.     inv.LinkRightHand ("")
  1346.     inv.LinkLeftHand ("")
  1347.     inv.LinkBack("")
  1348.  
  1349.     me.Data.UnlinkAll (EntityName, "")  # Dettatch arrows
  1350.     me.ResetWounds()
  1351.  
  1352.     if object_data[2]==0:
  1353.         me.SetMesh(ct.NoArmour)
  1354.     elif object_data[2]==1:
  1355.         me.SetMesh(ct.LowArmour)
  1356.     elif object_data[2]==2:
  1357.         me.SetMesh(ct.MedArmour)
  1358.     elif object_data[2]==3:
  1359.         me.SetMesh(ct.HighArmour)
  1360.     else:
  1361.         print "ERROR in Actions.TakeArmour , armour level!!!"
  1362.  
  1363.     #
  1364.     # Link again the stuff
  1365.     #
  1366.  
  1367.     # Right Back
  1368.     if rightback:
  1369.         inv.LinkRightHand (rightback)
  1370.         inv.LinkRightBack(rightback)
  1371.     # Left Back
  1372.     if leftback:
  1373.         inv.LinkLeftHand (leftback)
  1374.         inv.LinkLeftBack(leftback)
  1375.  
  1376.     # Right hand
  1377.     if right:
  1378.         inv.LinkRightHand (right)
  1379.     # Left hand
  1380.     if left:
  1381.         inv.LinkLeftHand (left)
  1382.  
  1383.  
  1384.     me.Data.armour_level=object_data[2]
  1385.     me.Data.armour_prot_factor=object_data[3]
  1386.  
  1387.     object.SubscribeToList("Pin")
  1388.  
  1389.     # to fix bug with taking objects later.....
  1390.     me.AnmEndedFunc(EntityName)
  1391.  
  1392.     return
  1393.  
  1394. def TakeMainAnm(EntityName):
  1395.     me = Bladex.GetEntity(EntityName)
  1396.     chartype = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  1397.  
  1398.     #MOvido mas abajo!!!
  1399.     #obj2inv=TakeObject2Inv(EntityName)
  1400.     #me.Data.obj2left= TakeObject2Left(EntityName)
  1401.  
  1402.  
  1403.     # Added by Manuel --->
  1404.     object_name=me.Data.pickup_entity
  1405.     ret=OnInitTake.OnInitTakeFunc(object_name)
  1406.  
  1407.     if OnInitTake.InitTakeDictionary.has_key(object_name) and not ret:
  1408.         return FALSE
  1409.  
  1410.     if not me.Data.pickup_entity:
  1411.         return FALSE
  1412.     # <---Added by Manuel
  1413.  
  1414.  
  1415.     inv=me.GetInventory()
  1416.     if inv.CarringObject(object_name):
  1417.         #print "---------CARRING IT ALREADY - Skipping"
  1418.         return FALSE
  1419.  
  1420.     obj2inv=TakeObject2Inv(EntityName)
  1421.     me.Data.obj2left= TakeObject2Left(EntityName)
  1422.  
  1423.     if Reference.GiveObjectFlag(object_name)==Reference.OBJ_ARMOUR:
  1424.         Bladex.AddScheduledFunc(Bladex.GetTime()+0.5, AuxFuncs.FadeTo, (0.5, 0.5))
  1425.         Bladex.AddScheduledFunc(Bladex.GetTime()+1.0, TakeArmour, (EntityName,))
  1426.  
  1427.  
  1428.     elif me.Data.last_heightdiff <= chartype.MaxTake1:
  1429.         if obj2inv:
  1430.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1431.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1432.             me.LaunchAnmType("tke_r_key00")
  1433.         else:
  1434.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1435.             me.LaunchAnmType("tke_r_01")
  1436.         ###Reference.debugprint (me.AnimName)
  1437.     elif me.Data.last_heightdiff <= chartype.MaxTake2:
  1438.         if obj2inv:
  1439.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1440.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1441.             me.LaunchAnmType("tke_r_key01")
  1442.         else:
  1443.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1444.             me.LaunchAnmType("tke_r_02")
  1445.         ###Reference.debugprint (me.AnimName)
  1446.     elif me.Data.last_heightdiff <= chartype.MaxTake3:
  1447.         if obj2inv:
  1448.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1449.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1450.             me.LaunchAnmType("tke_r_key02")
  1451.         else:
  1452.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1453.             me.LaunchAnmType("tke_r_03")
  1454.         ###Reference.debugprint (me.AnimName)
  1455.     elif me.Data.last_heightdiff <= chartype.MaxTake4:
  1456.         if obj2inv:
  1457.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1458.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1459.             me.LaunchAnmType("tke_r_key03")
  1460.         else:
  1461.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1462.             me.LaunchAnmType("tke_r_04")
  1463.         ###Reference.debugprint (me.AnimName)
  1464.     elif me.Data.last_heightdiff <= chartype.MaxTake5:
  1465.         if obj2inv:
  1466.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1467.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1468.             me.LaunchAnmType("tke_r_key04")
  1469.         else:
  1470.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1471.             me.LaunchAnmType("tke_r_05")
  1472.         ###Reference.debugprint (me.AnimName)
  1473.     else:
  1474.         print "Error in SubTake (last_height_diff) , Actions.py"
  1475.         if obj2inv:
  1476.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1477.             me.AddAnmEventFunc("Key_down",RemoveRightHandler)
  1478.             me.LaunchAnmType("tke_r_key04")
  1479.         else:
  1480.             me.AddAnmEventFunc("PickupEvent",PickupEventHandler)
  1481.             me.LaunchAnmType("tke_r_05")
  1482.         ###Reference.debugprint (me.AnimName)
  1483.  
  1484.     if Reference.GiveObjectFlag(object_name)==Reference.OBJ_ARMOUR:
  1485.         return
  1486.  
  1487.     if obj2inv:
  1488.         me.AnmEndedFunc=TakeStraightRecover
  1489.     else:
  1490.         me.AnmEndedFunc=MainTake2Inv
  1491.  
  1492.     return TRUE
  1493.  
  1494.  
  1495. def TakeStraightRecover(EntityName):
  1496.     me = Bladex.GetEntity(EntityName)
  1497.  
  1498.     me.Data.toggle4t_clearback= TRUE
  1499.     if (not me.Data.stuff_onback_b4) and (SthOnBack(EntityName) or (me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack)==Reference.OBJ_QUIVER)):
  1500.         me.AddAnmEventFunc("ChangeREvent",Toggle4TakingEvent)
  1501.         UnGraspString (EntityName,"UnGraspString")
  1502.         me.LaunchAnmType("Chg_r")
  1503.         #ToggleRight4Taking(EntityName)
  1504.  
  1505.  
  1506. def MainTake2Inv(EntityName):
  1507.     me = Bladex.GetEntity(EntityName)
  1508.  
  1509.     if not me.Data or not me.Data.pickup_entity:
  1510.         return
  1511.  
  1512.     #IS the object left in the right hand ?
  1513.     object_name = me.Data.pickup_entity
  1514.  
  1515.     if IsRightHandStandardObject(EntityName):
  1516.         ###Reference.debugprint("Object not 2 inv . Standard object.")
  1517.         return
  1518.     if IsRightHandAutomaticObject(EntityName):
  1519.         ###Reference.debugprint("Object not 2 inv . Automatic object.")
  1520.         return
  1521.  
  1522.     object_flag= Reference.GiveObjectFlag(object_name)
  1523.     if object_flag==Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW:
  1524.         return
  1525.  
  1526.     if (not me.Data.stuff_onback_b4) and (not SthOnBack(EntityName)) and IsRightHandWeaponObject(EntityName):
  1527.         ###Reference.debugprint("Nthing on back now nor b4 taking  . Skipping ToggleAfterTakeObj.")
  1528.         return
  1529.  
  1530.     ToggleAfterTakeObj(EntityName)
  1531.  
  1532. def PickupEventHandler(EntityName, EventName, force_take=TRUE):
  1533.     me = Bladex.GetEntity(EntityName)
  1534.  
  1535.     if EventName != "PickupEvent":
  1536.         ###Reference.debugprint(EntityName+":-( PickupEventHandler has unhandled event")
  1537.         return
  1538.  
  1539.     # Check the object is valid
  1540.     if not me.Data or not me.Data.pickup_entity:
  1541.         return
  1542.  
  1543.     if Bladex.GetEntity(me.Data.pickup_entity)==None:
  1544.         return
  1545.  
  1546.     object_name = me.Data.pickup_entity
  1547.  
  1548.     dist = B3DLib.GetXZDistance (EntityName, object_name )
  1549.     chartype = Bladex.GetCharType(me.CharType,me.CharTypeExt)
  1550.  
  1551.     # Is it too far?
  1552.     if dist > chartype.Reach:
  1553.         ReportMsg ("Not in reach")
  1554.         # to fix problem when 2 chars go to pickup same item (or enemy archer and player go for same arrow)
  1555.         return FALSE
  1556.  
  1557.     object =Bladex.GetEntity(object_name)
  1558.  
  1559.     if object.Parent:
  1560.         parent= Bladex.GetEntity(object.Parent)
  1561.         if parent.Person:
  1562.             # also to fix problem when 2 chars go to pickup same item (or enemy archer and player go for same arrow)
  1563.             return
  1564.         parent.Unlink(object)
  1565.  
  1566.     #print "PickupEventHandler "+EntityName+", "+EventName+", "+object_name
  1567.  
  1568.     ### /    Added by Dario    \ ####
  1569.     Ontake.OnTakeFunc(object_name)
  1570.     Stars.DeTwinkle(object_name)
  1571.     ### \   Added by Dario     / ####
  1572.  
  1573.     ###Reference.debugprint(EntityName+":-) Im picking up " + object_name)
  1574.     me.Data.selected_entity = None
  1575.     me.DelAnmEventFunc(EventName)
  1576.  
  1577.     if IsOneTooMany (EntityName, object_name):
  1578.         # Should never get here, as its checked before trying to take, but as scripts do weird things...
  1579.         if force_take:
  1580.             DropToMakeRoomFor(EntityName, object_name)
  1581.         else:
  1582.             print (EntityName+": Too many objects of this type: "+object_name)
  1583.             return
  1584.  
  1585.     # Get object type
  1586.     object_flag= Reference.GiveObjectFlag(object_name)
  1587.  
  1588.     inv = me.GetInventory()
  1589.  
  1590.     #NEW : So after taking , we launch the Chg_r anm...
  1591.     weapon_added=FALSE
  1592.     if not me.InvRight:        # Check right hand is still free
  1593.         if object_flag == Reference.OBJ_WEAPON:
  1594.             flag=Reference.GiveWeaponFlag(object_name)
  1595.             inv.AddWeapon(object_name,flag)
  1596.             WeaponName = Bladex.GetEntity(object_name).Kind
  1597.             weapon_added=TRUE
  1598.             if(netgame.GetNetState()==0):
  1599.                 if (not me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1600.                     # Race-Ordered Weapons
  1601.                     KnightWeaps = [    "QueenSword","IceSword","FireSword","Gladius","Orksword","Espadaelfica" ,
  1602.                                     "Espadaromana","Espadacurva","Dagesse","Cimitarra","EgyptSword","Espadafilo" ,
  1603.                                     "Espada","Maza","Maza2","Maza3"]
  1604.                                     
  1605.                     DwarfWeaps = [    "CrushHammer","FireAxe","IceHammer","Hacha","Hacha5","Hacha4","Hacha3",
  1606.                                     "Hacha6","Hacha2","Garrote","Martillo","Martillo2","Garropin","MazaDoble" ,
  1607.                                     "Garrote2","Martillo3"]
  1608.                     
  1609.                     AmazonWeaps = [    "TaiSword","SteelFeather","FireBo","LightEdge","Ninjato",
  1610.                                     "HookSword","Katana" ,"DoubleSword","Bo","Lanza","Naginata","Tridente",
  1611.                                     "Hachacuchilla","Naginata2","DeathBo","CrushBo"]
  1612.                     
  1613.                     BarbWeaps  = [    "FireBigSword","IceAxe","DalWeapon","Sablazo","Chaosword",
  1614.                                     "DeathSword","LongSword","Alfanje","BigSword","SawSword","FlatSword",
  1615.                                     "Eclipse","Guadanya","Hacha2hojas","RhinoClub","Hacharrajada"]
  1616.                     
  1617.                     char = Bladex.GetEntity("Player1")
  1618.                     
  1619.                     import Scorer
  1620.                     
  1621.                     if char.Kind == "Barbarian_N":
  1622.                         if  (
  1623.                             (not AmazonWeaps.count(WeaponName)) and
  1624.                             (not  DwarfWeaps.count(WeaponName)) and
  1625.                             (not KnightWeaps.count(WeaponName))
  1626.                             ):
  1627.                             Scorer.SlideTBS(0)
  1628.  
  1629.                     if char.Kind == "Amazon_N":
  1630.                         if  (
  1631.                             (not   BarbWeaps.count(WeaponName)) and
  1632.                             (not  DwarfWeaps.count(WeaponName)) and
  1633.                             (not KnightWeaps.count(WeaponName))
  1634.                             ):
  1635.                             Scorer.SlideTBS(0)
  1636.  
  1637.                     if char.Kind == "Dwarf_N":
  1638.                         if  (
  1639.                             (not AmazonWeaps.count(WeaponName)) and
  1640.                             (not   BarbWeaps.count(WeaponName)) and
  1641.                             (not KnightWeaps.count(WeaponName))
  1642.                             ):
  1643.                             Scorer.SlideTBS(0)
  1644.  
  1645.                     if char.Kind == "Knight_N":
  1646.                         if  (
  1647.                             (not AmazonWeaps.count(object_name)) and
  1648.                             (not DwarfWeaps.count(object_name)) and
  1649.                             (not BarbWeaps.count(object_name))
  1650.                             ):
  1651.                             Scorer.SlideTBS(0)
  1652.                     
  1653.         inv.LinkRightHand (object_name)
  1654.  
  1655.  
  1656.     if object_flag == Reference.OBJ_ITEM:
  1657.         ExtendedTakeObject(inv,object_name)
  1658.     elif object_flag == Reference.OBJ_SHIELD:
  1659.             ###Reference.debugprint("AddShield... " + object_name +" ok ?")
  1660.             inv.AddShield(object_name)
  1661.     elif object_flag == Reference.OBJ_WEAPON:
  1662.         if weapon_added==FALSE:
  1663.             flag=Reference.GiveWeaponFlag(object_name)
  1664.             inv.AddWeapon(object_name,flag)
  1665.             if (not me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1666.                 import Scorer
  1667.                 Scorer.SlideTBS(0)
  1668.  
  1669.     elif object_flag == Reference.OBJ_BOW:    #Corregir?
  1670.         inv.AddBow(object_name)
  1671.     elif object_flag == Reference.OBJ_QUIVER:
  1672.         AddQuiver(inv, object_name)
  1673.     elif object_flag == Reference.OBJ_STANDARD:
  1674.         pass
  1675.     elif object_flag == Reference.OBJ_KEY:
  1676.         inv.AddKey(object_name)
  1677.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1678.         inv.AddSpecialKey(object_name)
  1679.     elif object_flag == Reference.OBJ_TABLET:
  1680.         inv.AddTablet(object_name)
  1681.     elif object_flag == Reference.OBJ_USEME:
  1682.         #me.TakeObject(object_name)
  1683.         if IsValidForUsing (object_name, EntityName):
  1684.             ###Reference.debugprint(EntityName+":-) Will Use... " + object_name)
  1685.             me.Data.obj_used= Bladex.GetEntity(object_name)
  1686.             object= Bladex.GetEntity(object_name)
  1687.             object.Data.UsedBy= EntityName
  1688.             object.UseFunc(object_name, USE_FROM_TAKE)            # Need to link this object to the player first
  1689.         else:
  1690.             pass
  1691.             ###Reference.debugprint(EntityName+":-) Cannot use " + object_name)
  1692.     elif object_flag == Reference.OBJ_ARROW and not inv.HoldingBow:
  1693.         #SheatheArrow(inv, object_name)
  1694.         pass
  1695.  
  1696.     me.Data.RegisterObjectAsTaken(object_name)
  1697.  
  1698.  
  1699. #
  1700. # Throwing Actions
  1701. #
  1702. def ThrowTime2ThrowForce(throw_pressed):
  1703.     curve_f= 3.0
  1704.     if throw_pressed<Reference.THROW_TIME_MIN:
  1705.         MinThrowForce= Reference.THROW_TIME_MIN / Reference.THROW_TIME_MAX
  1706.         MinThrowForce= pow (MinThrowForce, curve_f)
  1707.         ThrowForce= throw_pressed/Reference.THROW_TIME_MIN * MinThrowForce
  1708.     elif throw_pressed<Reference.THROW_TIME_MAX:
  1709.         ThrowForce= min (throw_pressed, Reference.THROW_TIME_MAX) / Reference.THROW_TIME_MAX
  1710.         ThrowForce= pow (ThrowForce, curve_f)
  1711.     else:
  1712.         ThrowForce= 1.0
  1713.     return ThrowForce
  1714.  
  1715. def TestThrowRight(EntityName):
  1716.     me = Bladex.GetEntity(EntityName)
  1717.  
  1718.     throw_pressed = Bladex.GetTimeActionHeld ("Throw")
  1719.     if not throw_pressed:
  1720.         return
  1721.  
  1722.     #attack_pressed = Bladex.GetTimeActionHeld ("Attack")
  1723.     #if not attack_pressed:
  1724.     #    return
  1725.  
  1726.     #if throw_pressed < attack_pressed:
  1727.     #    return
  1728.  
  1729.     if throw_pressed < Reference.THROW_TIME_MIN:
  1730.         if(netgame.GetNetState()!=2):
  1731.             TryDropRight(EntityName)
  1732.         else:
  1733.             netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON,netgame.GetClientId()+" "+`-1`)
  1734.     else:
  1735.         if(netgame.GetNetState()!=2):
  1736.             # Clamp and normalize the force, record for later
  1737.             me.Data.ThrowForce = ThrowTime2ThrowForce (throw_pressed)
  1738.             StdThrowObject (EntityName)
  1739.         else:
  1740.             netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON,netgame.GetClientId()+" "+`ThrowTime2ThrowForce (throw_pressed)`)
  1741.  
  1742. def EnterThrowingMode(EntityName):
  1743.     pass
  1744.  
  1745. def TestThrowLeft(EntityName):
  1746.     me = Bladex.GetEntity(EntityName)
  1747.     #print(EntityName+": In TestThrowLeft")
  1748.     ###Reference.debugprint(EntityName+": In TestThrowLeft")
  1749.  
  1750.     throw_pressed = Bladex.GetTimeActionHeld ("Throw")
  1751.     ###Reference.debugprint(EntityName+": In TestThrowLeft: throw_pressed = "+`throw_pressed`)
  1752.     if not throw_pressed:
  1753.         return
  1754.  
  1755.     # Only capable so far of dropping with the left
  1756.     TryDropLeft (EntityName)
  1757.  
  1758. # Requires that me.Data.ThrowForce has been set up
  1759. def StdThrowObject(EntityName):
  1760.     me = Bladex.GetEntity(EntityName)
  1761.     ###Reference.debugprint(EntityName+": Im in StdThrowObject")
  1762.     # Have I got anything in the right hand
  1763.     statR = StatR(EntityName)
  1764.     if statR <> RA_NO_WEAPON and statR <>RA_BOW:
  1765.         ###Reference.debugprint(EntityName+': Right hand obj = '+me.InvRight)
  1766.         object = Bladex.GetEntity(me.InvRight)
  1767.         if IsValidForThrowing (object.Name):
  1768.             #if object.TestHit:
  1769.             #    ###Reference.debugprint(EntityName+": Pre-colliding - abandoning throw")
  1770.             #    return
  1771.             object.ExcludeHitFor(me)
  1772.             mass = object.Mass
  1773.             ###Reference.debugprint ("Mass is "+`mass`)
  1774.             if mass <= Reference.LightMassMax:
  1775.                 # In Combat Light Object Animation
  1776.                 me.AddAnmEventFunc("ThrowLightFacingEvent",ThrowReleaseEventHandler)
  1777.                 me.LaunchAnmType("1tw_l_f")
  1778.                 ###Reference.debugprint (me.AnimName)
  1779.             else:
  1780.                 # In Combat Heavy Object Animation
  1781.                 me.AddAnmEventFunc("ThrowHeavyFacingEvent",ThrowReleaseEventHandler)
  1782.                 me.LaunchAnmType("1tw_h_f")
  1783.                 ###Reference.debugprint (me.AnimName)
  1784.         else:
  1785.             ReportMsg ("Cannot be thrown")
  1786.             StdDropObject(EntityName)
  1787.  
  1788.  
  1789. def RemoveFromInventory (me, object, EventName):
  1790.  
  1791.     me.Unlink(object)
  1792.     inv = me.GetInventory()
  1793.  
  1794.     object_name = object.Name
  1795.  
  1796.     if object_name==me.InvRight:
  1797.         me.RemoveFromInventRight()
  1798.  
  1799.     if object_name==me.InvLeft:
  1800.         me.RemoveFromInventLeft()
  1801.  
  1802.     # Get object type
  1803.     object_flag= Reference.GiveObjectFlag(object_name)
  1804.  
  1805.     if object_flag == Reference.OBJ_ITEM:
  1806.         inv.RemoveObject(object_name)
  1807.     elif object_flag == Reference.OBJ_SHIELD:
  1808.         inv.RemoveShield(object_name)
  1809.     elif object_flag == Reference.OBJ_WEAPON:
  1810.         inv.RemoveWeapon(object_name)
  1811.     elif object_flag == Reference.OBJ_BOW:
  1812.         inv.RemoveBow(object_name)
  1813.     elif object_flag == Reference.OBJ_QUIVER:
  1814.         inv.RemoveQuiver(object_name)
  1815.     elif object_flag == Reference.OBJ_STANDARD:
  1816.         pass
  1817.     elif object_flag == Reference.OBJ_KEY:
  1818.         inv.RemoveKey(object_name)
  1819.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1820.         inv.RemoveSpecialKey(object_name)
  1821.     elif object_flag == Reference.OBJ_TABLET:
  1822.         inv.RemoveTablet(object_name)
  1823.     elif object_flag == Reference.OBJ_USEME:
  1824.         pass
  1825.  
  1826.     """
  1827.     if me.Name == "Player1":
  1828.         if object_flag == Reference.OBJ_ITEM:
  1829.             ObjectsControl.SetBODs()
  1830.         elif object_flag == Reference.OBJ_SHIELD or object_flag == Reference.OBJ_QUIVER:
  1831.             ShieldsControl.SetBODs()
  1832.         elif object_flag == Reference.OBJ_WEAPON or object_flag == Reference.OBJ_BOW:
  1833.             WeaponsControl.SetBODs()
  1834.     """
  1835.  
  1836. def ThrownWeaponStopFunc(EntityName):
  1837.     object= Bladex.GetEntity(EntityName)
  1838.     #print "Thrown object stopping"
  1839.     if object:
  1840.         object.MessageEvent(MESSAGE_STOP_WEAPON,0,0)
  1841.         object.MessageEvent(MESSAGE_STOP_TRAIL,0,0)
  1842.  
  1843.         try:
  1844.             if object.Data.PrevHitFunc:
  1845.                 object.HitFunc= object.Data.PrevHitFunc
  1846.                 object.Data.PrevHitFunc= None
  1847.                 object.HitFunc (EntityName)
  1848.         except AttributeError:
  1849.             pass
  1850.     #object.Data.ThrownBy= None
  1851.  
  1852. def ThrownWeaponInflictHitFunc(EntityName, VictimName, ImpX, ImpY, ImpZ):
  1853.     object= Bladex.GetEntity(EntityName)
  1854.     victim= Bladex.GetEntity(VictimName)
  1855.     print "Thrown object hitting "+VictimName
  1856.     object.MessageEvent(MESSAGE_STOP_WEAPON,0,0)
  1857.     if object.Data.PrevInflictHitFunc:
  1858.         object.InflictHitFunc= object.Data.PrevInflictHitFunc
  1859.         object.Data.PrevInflictHitFunc= None
  1860.         object.InflictHitFunc (EntityName, VictimName, ImpX, ImpY, ImpZ)
  1861.     else:
  1862.         object.InflictHitFunc=0
  1863.     #object.Data.ThrownBy= None
  1864.     #if victim.Life <= 0:
  1865.     #    node= 0
  1866.     #    victim.LinkToNode(object,node)
  1867.  
  1868. def AutoCalcThrow (d, h, V, g):
  1869.  
  1870.     g2= g**2
  1871.     V2= V**2
  1872.     V4= V**4
  1873.     d2= d**2
  1874.     d4= d**4
  1875.  
  1876.     a= h**2+d2
  1877.     b= d2*(-1.0-(h*g/V2))
  1878.     c= 0.25*g2*d4/V4
  1879.  
  1880.     sq_term= b**2-4*a*c
  1881.  
  1882.     if sq_term<0.0:
  1883.         print "Auto calc doesn't reach"
  1884.         return -PI*0.25, 2.0
  1885.     else:
  1886.         sq_term= math.sqrt(sq_term)
  1887.         k= (-b+sq_term)/(2.0*a)
  1888.         angle= -math.acos(math.sqrt(k))
  1889.         time= d / (V*math.cos(angle))
  1890.         if abs(h-(V*math.sin(angle)*time+0.5*g*time*time)) > 0.001:
  1891.             angle= -angle
  1892.             time= d / (V*math.cos(angle))
  1893.         print "Auto calc gives angle: " + `angle` + " with time: " +`time`
  1894.         return angle, time
  1895.  
  1896. def ThrowReleaseEventHandler(EntityName, EventName):
  1897.  
  1898.     me = Bladex.GetEntity(EntityName)
  1899.     ###Reference.debugprint(EntityName+": Im in ThrowReleaseEventHandler")
  1900.  
  1901.  
  1902.     if EventName=="ThrowLeftEvent":
  1903.         print "LeftThrow"
  1904.         if me.InvLeft=="None" or not me.InvLeft:
  1905.             return
  1906.         object = Bladex.GetEntity(me.InvLeft)
  1907.     else:
  1908.         if me.InvRight=="None" or not me.InvRight:
  1909.             return
  1910.         object = Bladex.GetEntity(me.InvRight)
  1911.  
  1912.     try:
  1913.         object.Data.ThrowReleaseEventHandler (me.Name, EventName)
  1914.     except AttributeError:
  1915.         if object.TestHit:
  1916.             ###Reference.debugprint(EntityName+": Pre-colliding - abandoning throw")
  1917.             return
  1918.  
  1919.         # Remove from inventory
  1920.         RemoveFromInventory (me, object, EventName)
  1921.         # Calculate impulse depending on event type
  1922.  
  1923.         # calculate impulse from keypress duration multiplier and character strength
  1924.         F= me.Data.ThrowForce*34000.0
  1925.  
  1926.         if me.InCombat:
  1927.             target= Bladex.GetEntity(me.ActiveEnemy)
  1928.             target_pos= target.Position
  1929.             source_pos= object.Position
  1930.             x= target_pos[0]-source_pos[0]
  1931.             y= target_pos[1]-source_pos[1]
  1932.             z= target_pos[2]-source_pos[2]
  1933.  
  1934.             angle, time= AutoCalcThrow (math.sqrt(x*x+z*z), y, F/object.Mass,+9800.0)
  1935.         elif EventName == "ThrowLightFacingEvent":
  1936.             angle= -PI*0.0625 # max angle/4
  1937.         elif EventName == "ThrowHeavyFacingEvent":
  1938.             angle= -PI*0.125 # max angle/2
  1939.         else:
  1940.             angle= -PI*0.0625 # max angle/4
  1941.  
  1942.         impulse = me.Rel2AbsVector(0.0, -math.cos(angle)*F, -math.sin(angle)*F)
  1943.  
  1944.         if me.InCombat:
  1945.             angle= B3DLib.Pos2PosXZAngle(source_pos[0], source_pos[1], source_pos[2],target_pos[0], target_pos[1], target_pos[2])
  1946.             diff_angle= min (max (B3DLib.DiffAngle(angle, me.Angle), -FACINGANGLE), FACINGANGLE)
  1947.             x,y,z= impulse
  1948.             cos_ang= math.cos(diff_angle); sin_ang= math.sin(diff_angle)
  1949.             impulse = (x*cos_ang-z*sin_ang, y, x*sin_ang+z*cos_ang)
  1950.  
  1951.         object.Impulse(impulse[0], impulse[1], impulse[2])
  1952.  
  1953.         throw_style= Reference.THR_SPINNING
  1954.         if Reference.EntitiesObjectData.has_key(object.Name):
  1955.             if Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_WEAPON or Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_STANDARD:
  1956.                 weaponData= Reference.EntitiesObjectData[object.Name]
  1957.                 if len(weaponData) > 4:
  1958.                     throw_style= weaponData[4]
  1959.         else:
  1960.             kind = Bladex.GetEntity(object.Name).Kind
  1961.             if Reference.DefaultObjectData.has_key(kind):
  1962.                 if Reference.DefaultObjectData[kind][0] == Reference.OBJ_WEAPON or Reference.DefaultObjectData[kind][0] == Reference.OBJ_STANDARD:
  1963.                     weaponData = Reference.DefaultObjectData[kind]
  1964.                     if len(weaponData) > 4:
  1965.                         throw_style= weaponData[4]
  1966.         # exclude people from collision
  1967.         object.ExclusionMask= object.ExclusionMask | B_SOLID_MASK_PERSON
  1968.  
  1969.         if throw_style == Reference.THR_SPINNING:
  1970.             # Add an angular velocity component as well...
  1971.             print object.AngularVelocity
  1972.             axis= object.GetDummyAxis("1H_R", 0.0, 1.0, 0.0)
  1973.             mass= object.Mass
  1974.             print mass
  1975.             scale = TWOPI*10/mass
  1976.             object.AngularVelocity=axis[0]*scale,axis[1]*scale,axis[2]*scale
  1977.         object.MessageEvent(MESSAGE_START_WEAPON,0,0)
  1978.         object.MessageEvent(MESSAGE_START_TRAIL,0,0)
  1979.         InitDataField.Initialise(object)
  1980.         object.Data.PrevHitFunc= None
  1981.         #object.Data.PrevHitFunc= object.HitFunc
  1982.         #object.HitFunc= ThrownWeaponStopFunc
  1983.         Bladex.AddScheduledFunc(Bladex.GetTime()+2.0, ThrownWeaponStopFunc,(object.Name,),"Stop Weapon: "+object.Name)
  1984.         object.Data.PrevInflictHitFunc= object.InflictHitFunc
  1985.         object.InflictHitFunc= ThrownWeaponInflictHitFunc
  1986.         object.Data.ThrownBy= me
  1987.  
  1988.     me.DelAnmEventFunc(EventName)
  1989.  
  1990. #
  1991. # Dropping Actions
  1992. #
  1993.  
  1994.  
  1995. def StdDropObject(EntityName):
  1996.     me = Bladex.GetEntity(EntityName)
  1997.     ###Reference.debugprint(EntityName+": Im in StdDropObject")
  1998.     if TryDropRight(EntityName):
  1999.         pass
  2000.         ###Reference.debugprint(EntityName+": Dropping Right")
  2001.     elif TryDropLeft(EntityName):
  2002.         pass
  2003.         ###Reference.debugprint(EntityName+": Dropping Left")
  2004.     else:
  2005.         pass
  2006.         ###Reference.debugprint(EntityName+": Nothing to Drop")
  2007.  
  2008. def TryDropRight (EntityName):
  2009.     me = Bladex.GetEntity(EntityName)
  2010.     # Have I got anything in the right hand
  2011.     statR = StatR(EntityName)
  2012.     if statR <> RA_NO_WEAPON:
  2013.         ###Reference.debugprint(EntityName+": Right hand obj = "+me.InvRight)
  2014.         object = Bladex.GetEntity(me.InvRight)
  2015.         if IsValidForDropping (object.Name):
  2016.             object.ExcludeHitFor(me)
  2017.             #if object.TestHit:
  2018.             #    ###Reference.debugprint(EntityName+": Pre-colliding - abandoning drop")
  2019.             #    return FALSE
  2020.             if statR == RA_2H_OBJECT:
  2021.                 # 2 Handed Object Animation
  2022.                 me.AddAnmEventFunc("Drop2HandedEvent",DropReleaseEventHandler)
  2023.                 me.LaunchAnmType("drp_2o")
  2024.                 ###Reference.debugprint (me.AnimName)
  2025.                 return    TRUE
  2026.             else:
  2027.                 # Right Handed Object Animation
  2028.                 me.AddAnmEventFunc("DropRightEvent",DropReleaseEventHandler)
  2029.                 me.Attack=0
  2030.                 me.LaunchAnmType("drp_r")
  2031.                 #The next : for not attacking just after droping!
  2032.  
  2033.                 ###Reference.debugprint (me.AnimName)
  2034.                 return    TRUE
  2035.         else:
  2036.             ReportMsg ("Cannot be dropped")
  2037.             return FALSE
  2038.     else:
  2039.         return FALSE
  2040.  
  2041. def TryDropLeft (EntityName):
  2042.     me = Bladex.GetEntity(EntityName)
  2043.     statL=StatL(me.Name)
  2044.     if statL <> LA_NO_WEAPON and statL <> LA_BOW:
  2045.         ###Reference.debugprint(EntityName+": Left hand obj = "+me.InvLeft)
  2046.         object = Bladex.GetEntity(me.InvLeft)
  2047.         if IsValidForDropping (object.Name):
  2048.             object.ExcludeHitFor(me)
  2049.             #if object.TestHit:
  2050.             #    ###Reference.debugprint(EntityName+": Pre-colliding - abandoning drop")
  2051.             #    return FALSE
  2052.  
  2053.             # Left Handed Object Animation
  2054.             me.AddAnmEventFunc("DropLeftEvent",DropReleaseEventHandler)
  2055.             me.LaunchAnmType("drp_l")
  2056.             ###Reference.debugprint (me.AnimName)
  2057.             return TRUE
  2058.         else:
  2059.             ReportMsg ("Cannot be dropped")
  2060.     else:
  2061.         return FALSE
  2062.  
  2063. def DropReleaseEventHandler(EntityName, EventName, TestHit=TRUE):
  2064.     me = Bladex.GetEntity(EntityName)
  2065.     ###Reference.debugprint(EntityName+": Im in DropReleaseEventHandler")
  2066.  
  2067.     if EventName == "DropLeftEvent":
  2068.         object = Bladex.GetEntity(me.InvLeft)
  2069.     else:
  2070.         object = Bladex.GetEntity(me.InvRight)
  2071.  
  2072.     try:
  2073.         object.Data.DropReleaseEventHandler (me.Name, EventName)
  2074.  
  2075.     except AttributeError:
  2076.         if TestHit and object.TestHit:
  2077.             return
  2078.  
  2079.         RemoveFromInventory (me, object, EventName)
  2080.  
  2081.         if EventName == "DropLeftEvent":
  2082.             impulse = me.Rel2AbsVector(500.0, -750.0, 0.0)
  2083.         elif EventName == "Drop2HandedEvent":
  2084.             impulse = me.Rel2AbsVector(0.0, -750.0, 0.0)
  2085.         else:
  2086.             impulse = me.Rel2AbsVector(-1000.0, -1500.0, 0.0)
  2087.  
  2088.         object.Impulse(impulse[0],impulse[1],impulse[2])
  2089.         object.ExcludeHitFor(me)
  2090.         me.DelAnmEventFunc(EventName)
  2091.  
  2092. ################
  2093. #
  2094. #
  2095. #
  2096. ################
  2097.  
  2098.  
  2099. def SqDistanceToGpj(entity):
  2100.     global Gpj
  2101.     return(Gpj.SQDistance2(entity))
  2102.  
  2103. def SthOnBack(EntityName):
  2104.     me=Bladex.GetEntity(EntityName)
  2105.     if me.InvLeftBack:
  2106.         return TRUE
  2107.     if me.InvRightBack:
  2108.         if Reference.GiveObjectFlag(me.InvRightBack)==Reference.OBJ_QUIVER:
  2109.             return FALSE
  2110.         else:
  2111.             return TRUE
  2112.     else:
  2113.         return FALSE
  2114.  
  2115. def TwoHandedWeaponOnBack(EntityName):
  2116.     me=Bladex.GetEntity(EntityName)
  2117.     if SthOnBack(EntityName) and me.InvRightBack:
  2118.         back_object_flag= Reference.GiveObjectFlag(me.InvRightBack)
  2119.         if back_object_flag==Reference.OBJ_WEAPON:
  2120.             w_flag=Reference.GiveWeaponFlag(me.InvRightBack)
  2121.             if w_flag<>Reference.W_FLAG_1H:
  2122.                 return TRUE
  2123.     return FALSE
  2124.  
  2125. def Left2InvEvent(pj_name,event):
  2126.     me=Bladex.GetEntity(pj_name)
  2127.     me.DelAnmEventFunc(event)
  2128.     inv=me.GetInventory()
  2129.     if me.InvLeft:
  2130.         inv.LinkLeftHand("None")
  2131.  
  2132. def Left2BackEvent(pj_name,event):
  2133.     me=Bladex.GetEntity(pj_name)
  2134.     me.DelAnmEventFunc(event)
  2135.     inv=me.GetInventory()
  2136.     if me.InvLeft:
  2137.         inv.LinkLeftBack(me.InvLeft)
  2138.  
  2139.  
  2140.  
  2141.  
  2142. def ToggleWEvent(pj_name,event):
  2143.     me=Bladex.GetEntity(pj_name)
  2144.  
  2145.  
  2146.  
  2147.     #
  2148.     # So the standard obnject that could NOT ve dropped at the beggining ( cause inside B_world ) , do NOT dissapear!
  2149.     #
  2150.     if IsRightHandStandardObject(pj_name):
  2151.         #print "TryDropRight is ok"
  2152.         DropReleaseEventHandler(pj_name, "DropRightEvent")
  2153.         if me.InvRight:
  2154.             print "Actions.ToggleWEvent-> Could not drop standard object!"
  2155.             return FALSE
  2156.         me.Wuea=Reference.WUEA_ENDED
  2157.  
  2158.  
  2159.  
  2160.     if event=="ChangeRLEvent":
  2161.         me.DelAnmEventFunc("ChangeRLEvent")
  2162.     elif event=="ChangeREvent":
  2163.         me.DelAnmEventFunc("ChangeREvent")
  2164.     elif event=="ChangeLEvent":
  2165.         me.DelAnmEventFunc("ChangeLEvent")
  2166.     else:
  2167.         print "ToggleWEvent : Unexpected error! \n"
  2168.  
  2169.     inv=me.GetInventory()
  2170.     tmp_rback=me.InvRightBack
  2171.     tmp_lback=me.InvLeftBack
  2172.     if tmp_rback:
  2173.         if Reference.GiveObjectFlag(tmp_rback)==Reference.OBJ_QUIVER:
  2174.             tmp_rback=""
  2175.  
  2176.     something_on_back= SthOnBack(pj_name)
  2177.     inv.LinkBack("None")
  2178.  
  2179.     add_quiver=0
  2180.     if something_on_back and (event=="ChangeRLEvent" or event=="ChangeREvent"):
  2181.  
  2182.         if me.InvRight:
  2183.             ###Reference.debugprint ("Removeing right hand thing on ToggleWEvent")
  2184.             inv.LinkRightHand("None")
  2185.         #inv.LinkBack("None") #Only here ! It deal with BOTH of them
  2186.  
  2187.         if tmp_lback and Reference.GiveObjectFlag(tmp_lback)==Reference.OBJ_BOW:
  2188.             add_quiver=1
  2189.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW:
  2190.             add_quiver=1
  2191.  
  2192.  
  2193.     if event=="ChangeRLEvent" or event=="ChangeREvent":
  2194.         if me.InvRight:
  2195.             if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW and me.InvRight and Reference.GiveObjectFlag(me.InvRight)==Reference.OBJ_ARROW:
  2196.                 SheatheArrow(inv, me.InvRight)    # We must be carrying an arrow in the right hand, lets sheathe it
  2197.             else:
  2198.                 inv.LinkBack(me.InvRight)
  2199.         else:
  2200.             if inv.HoldingBow:
  2201.                 des_quiver_name=inv.GetSelectedQuiver()
  2202.                 if des_quiver_name:
  2203.                     inv.SetCurrentQuiver(des_quiver_name)
  2204.                     inv.LinkRightBack(des_quiver_name)
  2205.                 #print "BUG KK"
  2206.  
  2207.         if not tmp_rback:
  2208.             inv.LinkRightHand("None")
  2209.         else:
  2210.             inv.LinkRightHand(tmp_rback)
  2211.             tmp_rback=""
  2212.  
  2213.     if event=="ChangeRLEvent" or event=="ChangeLEvent":
  2214.         #inv.LinkBack("None")
  2215.         if tmp_rback:
  2216.             print "Pseudo bug? ERROR , MIRAR"
  2217.             inv.LinkBack(tmp_rback)
  2218.         if me.InvLeft:
  2219.             inv.LinkBack(me.InvLeft)
  2220.         if not tmp_lback:
  2221.             inv.LinkLeftHand("None")
  2222.         else:
  2223.             inv.LinkLeftHand(tmp_lback)
  2224.  
  2225.     if add_quiver:
  2226.         UnSheatheArrow(inv)
  2227.  
  2228.  
  2229.  
  2230. def StdToggleWeapons(EntityName):
  2231.  
  2232.     me=Bladex.GetEntity(EntityName)
  2233.  
  2234.     #Are we in combat mode
  2235.     #If so , abort it and return
  2236.     if me.ActiveEnemy:
  2237.         ###Reference.debugprint ("StdToggleeapons - Aborting combat mode")
  2238.         me.SetActiveEnemy("")
  2239.         me.Data.time_deactive_enemy=Bladex.GetTime()
  2240.         return
  2241.  
  2242.     if me.OnFloor==0:
  2243.         return
  2244.  
  2245.     if me.AnmEndedFunc:
  2246.         return FALSE
  2247.  
  2248.     inv= me.GetInventory()
  2249.  
  2250.     right_standard=IsRightHandStandardObject(EntityName)
  2251.     drop_right=0
  2252.     #pdb.set_trace()
  2253.     if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)<>Reference.OBJ_BOW and me.InvRightBack: #and (not me.Attack and not me.Block):
  2254.         if not me.Attack and not me.Block:
  2255.             me.AddAnmEventFunc("ChangeLEvent",Left2BackEvent)
  2256.             me.LaunchAnmType("Chg_l")
  2257.             return
  2258.         else:
  2259.             me.AddAnmEventFunc("ChangeREvent",ToggleWEvent)
  2260.             me.LaunchAnmType("Chg_r")
  2261.             return
  2262.     elif ((me.InvRight and right_standard==1)) and (me.InvLeft or me.InvLeftBack) and me.InvRightBack and not inv.HasBowOnBack:
  2263.         me.AddAnmEventFunc("ChangeLEvent",ToggleWEvent)
  2264.         me.LaunchAnmType("Chg_l")
  2265.         return
  2266.     elif ((me.InvRight and right_standard==0) or me.InvRightBack) and (me.InvLeft or me.InvLeftBack):
  2267.         drop_right=1
  2268.         if inv.HasBowOnBack:
  2269.             if right_standard:
  2270.                 object= Bladex.GetEntity(me.InvRight)
  2271.                 object.ExcludeHitFor(me)
  2272.                 if not object.TestHit:
  2273.                     if TryDropRight(EntityName):
  2274.                         DropReleaseEventHandler(EntityName, "DropRightEvent")
  2275.                         me.Wuea=Reference.WUEA_ENDED
  2276.                     else:
  2277.                         me.Wuea=Reference.WUEA_ENDED
  2278.                         return
  2279.                 else:
  2280.                     ReportMsg ("Cannot be dropped")
  2281.                     return
  2282.     elif ((me.InvRight and right_standard==0) or me.InvRightBack) and (not me.InvLeft and not me.InvLeftBack):
  2283.         drop_right=2
  2284.     elif (not me.InvRight and not me.InvRightBack) and (me.InvLeft or me.InvLeftBack):
  2285.         if inv.HasBowOnBack:
  2286.             if right_standard:
  2287.                 object= Bladex.GetEntity(me.InvRight)
  2288.                 object.ExcludeHitFor(me)
  2289.                 if not object.TestHit:
  2290.                     if TryDropRight(EntityName):
  2291.                         DropReleaseEventHandler(EntityName, "DropRightEvent")
  2292.                         me.Wuea=Reference.WUEA_ENDED
  2293.                     else:
  2294.                         me.Wuea=Reference.WUEA_ENDED
  2295.                         return
  2296.                 else:
  2297.                     ReportMsg ("Cannot be dropped")
  2298.                     return
  2299.  
  2300.             me.AddAnmEventFunc("ChangeRLEvent",ToggleWEvent)
  2301.             me.LaunchAnmType("Chg_r_l")
  2302.             return
  2303.         else:
  2304.             me.AddAnmEventFunc("ChangeLEvent",ToggleWEvent)
  2305.             me.LaunchAnmType("Chg_l")
  2306.             return
  2307.     else:
  2308.         return
  2309.  
  2310.  
  2311.  
  2312.     if drop_right<>0 and IsRightHandStandardObject(EntityName):
  2313.         if TryDropRight(EntityName):
  2314.             DropReleaseEventHandler(EntityName, "DropRightEvent")
  2315.         me.Wuea=Reference.WUEA_ENDED
  2316.  
  2317.  
  2318.     if drop_right==1:
  2319.         me.AddAnmEventFunc("ChangeRLEvent",ToggleWEvent)
  2320.         me.LaunchAnmType("Chg_r_l")
  2321.     elif drop_right==2:
  2322.         me.AddAnmEventFunc("ChangeREvent",ToggleWEvent)
  2323.         me.LaunchAnmType("Chg_r")
  2324.     else:
  2325.         print "ERROR - ToggleW"
  2326.  
  2327. # Added by Dario
  2328. def FreeBothHands(EntityName,CallBack=None,Params=(),ForceNow = 1):
  2329.     me=Bladex.GetEntity(EntityName)
  2330.  
  2331.     if IsRightHandStandardObject(EntityName):
  2332.         if TryDropRight(EntityName):
  2333.             DropReleaseEventHandler(EntityName, "DropRightEvent")
  2334.         me.Wuea=Reference.WUEA_ENDED
  2335.  
  2336.     if (me.InvRight) or (me.InvLeft):
  2337.         if ForceNow:
  2338.             me.Wuea=Reference.WUEA_ENDED
  2339.             me.SetTmpAnmFlags(1,1,1,0,5,1,0)
  2340.             me.LaunchAnmType("rlx")
  2341.             me.Wuea=Reference.WUEA_ENDED
  2342.             me.SetTmpAnmFlags(1,1,1,0,5,1,0)
  2343.         StdToggleWeapons(EntityName)
  2344.  
  2345.  
  2346.         if CallBack:
  2347.             Bladex.AddScheduledFunc(Bladex.GetTime()+2.0, CallBack,Params)
  2348.         return 0
  2349.     if CallBack:
  2350.         Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, CallBack,Params)
  2351.     return 1
  2352.  
  2353.  
  2354. def RelaxTurn180(EntityName):
  2355.     me=Bladex.GetEntity(EntityName)
  2356.     me.LaunchAnmType("rlx_turn")
  2357.  
  2358.  
  2359. import BInput
  2360.  
  2361.  
  2362. def FrwdDown(EntityName):
  2363.     me=Bladex.GetEntity(EntityName)
  2364.     if netgame.GetNetState() != 2:
  2365.         if me.InCombat:
  2366.             return
  2367.  
  2368.     binput_time_down=BInput.GetInputManager().GetTimeActionActivated("FrwdDown")
  2369.     diff=binput_time_down-me.Data.last_frwdup
  2370.  
  2371.     if diff>0.0 and diff<0.125:
  2372.         me=Bladex.GetEntity(EntityName)
  2373.         me.Run=1
  2374.  
  2375.  
  2376. def FrwdUp(EntityName):
  2377.     me=Bladex.GetEntity(EntityName)
  2378.     if netgame.GetNetState() != 2:
  2379.         if me.InCombat:
  2380.             return
  2381.  
  2382.     me.Data.last_frwdup=BInput.GetInputManager().GetTimeActionActivated("FrwdUp")
  2383.  
  2384.  
  2385.     if me.Gob==FALSE:
  2386.         me.Run=0
  2387.  
  2388.  
  2389. def BrwdDown(EntityName):
  2390.     me=Bladex.GetEntity(EntityName)
  2391.     if netgame.GetNetState() != 2:
  2392.         if me.InCombat:
  2393.             return
  2394.  
  2395.     binput_time_down=BInput.GetInputManager().GetTimeActionActivated("BrwdDown")
  2396.     diff=Bladex.GetTime()-me.Data.last_brwdup
  2397.  
  2398.     if diff>0.0 and diff<0.125:
  2399.         me=Bladex.GetEntity(EntityName)
  2400.         me.Run=1
  2401.  
  2402.  
  2403. def BrwdUp(EntityName):
  2404.     me=Bladex.GetEntity(EntityName)
  2405.     if netgame.GetNetState() != 2:
  2406.         if me.InCombat:
  2407.             return
  2408.  
  2409.     me.Data.last_brwdup=BInput.GetInputManager().GetTimeActionActivated("BrwdUp")
  2410.  
  2411.     if me.Gof==FALSE:
  2412.         me.Run=0
  2413.  
  2414.  
  2415.  
  2416.  
  2417. # BowStuff
  2418.  
  2419.  
  2420. def TakeArrowEventHandler(EntityName, EventName):
  2421.     me= Bladex.GetEntity(EntityName)
  2422.     if me:
  2423.         #print EntityName+" TakeArrowEventHandler, "+me.AnimName+": "+`me.AnmPos`
  2424.         inv= me.GetInventory()
  2425.         UnSheatheArrow(inv)
  2426.         #if me.InvRight:
  2427.         #    print EntityName+" TakeArrowEventHandler: aimpressed: "+`me.Data.AimPressed`
  2428.  
  2429. def CurrentlyBowing(EntityName):
  2430.     me= Bladex.GetEntity(EntityName)
  2431.     anm= me.AnimName
  2432.     return (anm=="B1" or anm=="B2" or anm=="B3" or anm=="b1" or anm=="b2" or anm=="b3")
  2433.  
  2434. def InitBowing(EntityName):
  2435.     #print EntityName+" InitBowing"
  2436.     me= Bladex.GetEntity(EntityName)
  2437.     cam= Bladex.GetEntity("Camera")
  2438.     if EntityName=='Player1':
  2439.         try:
  2440.             if me.Data.LastPViewType==None:
  2441.                 me.Data.LastPViewType= cam.PViewType
  2442.         except AttributeError:
  2443.             me.Data.LastPViewType= cam.PViewType
  2444.         try:
  2445.             if me.Data.LastReturns==None:
  2446.                 me.Data.LastReturns= me.Returns
  2447.         except AttributeError:
  2448.             me.Data.LastReturns= me.Returns
  2449.         cam.PViewType= 3
  2450.     me.Returns= 0
  2451.     me.Aim= 1
  2452.     me.Data.AimPressed= 1
  2453.     me.Accuracy= CharStats.GetCharAccuracy(me.Kind, me.Level)
  2454.     me.AimOffTarget= TWOPI
  2455.  
  2456. def TestDrawBow(EntityName):
  2457.     me= Bladex.GetEntity(EntityName)
  2458.     #print EntityName+" TestDrawBow"
  2459.     #pdb.set_trace()
  2460.     # Are we carrying a bow
  2461.     if me.Aim==0 or not CurrentlyBowing(EntityName):
  2462.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft)==Reference.OBJ_BOW:
  2463.             # check we can interrupt the animation
  2464.             if me.Wuea==Reference.WUEA_WAIT:
  2465.                 if (me.AnimName[:3]=="Rlx" or me.AnimName[:3]=="rlx"):
  2466.                     me.Wuea=Reference.WUEA_NONE
  2467.                 else: return
  2468.             # Are we carrying an arrow
  2469.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight)==Reference.OBJ_ARROW:
  2470.                 InitBowing(EntityName)
  2471.                 GraspString (EntityName,"GraspString")
  2472.                 me.SetTmpAnmFlags(1,0,1,1,2,0)
  2473.                 me.LaunchAnmType ("b1")
  2474.                 arrow= Bladex.GetEntity(me.InvRight)
  2475.                 tensar_sound=Bladex.CreateEntity(arrow.Name+"RedrawSound", "Entity Sound", 0, 0, 0)
  2476.                 tensar_sound.SetSound("..\\..\\Sounds\\M-CREAKCUERDA-3b.wav")
  2477.                 tensar_sound.MinDistance=5000
  2478.                 tensar_sound.MaxDistance=10000
  2479.                 arrow.Link(tensar_sound)
  2480.                 tensar_sound.PlaySound(0)
  2481.                     # Problems: Cannot get the animation to stay on last frame, or allow rotation
  2482.             # else if we have arrows draw an arrow and continue
  2483.             elif not CurrentlyBowing(EntityName):
  2484.                 inv=me.GetInventory()
  2485.                 des_quiver_name=inv.GetSelectedQuiver()
  2486.                 if des_quiver_name:
  2487.                     inv.SetCurrentQuiver(des_quiver_name)
  2488.                     inv.LinkRightBack(des_quiver_name)
  2489.                     quiver= Bladex.GetEntity(des_quiver_name)
  2490.                     if quiver and quiver.Data.NumberOfArrows() > 0:
  2491.                         InitBowing(EntityName)
  2492.                         if me.Wuea==Reference.WUEA_WAIT:
  2493.                             print "Trying to draw bow during other animation, wait and try again"
  2494.                         else:
  2495.                             me.LaunchAnmType ("b2")
  2496.  
  2497.  
  2498. def EndBowMode(EntityName):
  2499.     #print EntityName+" in EndBowMode"
  2500.     me= Bladex.GetEntity(EntityName)
  2501.     #print EntityName+" EndBowMode"
  2502.     try:
  2503.         if me.Data.LastPViewType!=None:
  2504.             cam= Bladex.GetEntity("Camera")
  2505.             cam.PViewType= me.Data.LastPViewType
  2506.             me.Data.LastPViewType= None
  2507.     except AttributeError:
  2508.         pass
  2509.     try:
  2510.         if me.Data.LastReturns!=None:
  2511.             me.Returns= me.Data.LastReturns
  2512.             me.Data.LastReturns= None
  2513.     except AttributeError:
  2514.         pass
  2515.     me.Aim= 0
  2516.     me.Data.AimPressed= 0
  2517.  
  2518. def TestReleaseArrow(EntityName):
  2519.     me= Bladex.GetEntity(EntityName)
  2520.     #print EntityName+' TestReleaseArrow setting AimPressed to 0'
  2521.     me.Data.AimPressed= 0
  2522.     if not CurrentlyBowing(EntityName):
  2523.         #print "    exited abnormally"
  2524.         EndBowMode(EntityName)
  2525.  
  2526.  
  2527. def EndDrawBowEventHandler(EntityName, EventName):
  2528.     me= Bladex.GetEntity(EntityName)
  2529.     #print EntityName+" EndDrawBowEventHandler, "+me.AnimName+": "+`me.AnmPos`
  2530.     if me.Data.AimPressed==0:
  2531.         me.Aim= 0
  2532.         arrow= Bladex.GetEntity(me.InvRight)
  2533.         if arrow:
  2534.             #print EntityName+" EndDrawBowEventHandler:Letting Arrow Fly"
  2535.             # exclude people from collision
  2536.             #arrow.ExclusionMask= arrow.ExclusionMask | B_SOLID_MASK_PERSON
  2537.  
  2538.             # play arrow sound
  2539.             me.Unlink(arrow)
  2540.             me.RemoveFromInventRight()
  2541.             UnGraspString (EntityName,"UnGraspString")
  2542.             # Release the arrow
  2543.             arrow.ExcludeHitFor(me)
  2544.             arrow.PutToWorld()
  2545.  
  2546.             # Let the arrow fly along its own Z axis
  2547.             if me.Data.NPC:
  2548.                 vx,vy,vz= me.AimVector
  2549.             else:
  2550.                 vx,vy,vz= arrow.Rel2AbsVector(0,0,-40000)
  2551.             arrow.Fly(vx,vy,vz)
  2552.  
  2553.             arrow.MessageEvent(MESSAGE_START_WEAPON,0,0)
  2554.             arrow.MessageEvent(MESSAGE_START_TRAIL,0,0)
  2555.  
  2556.             # Arrange for the MESSAGE_STOP_WEAPON to be sent
  2557.             InitDataField.Initialise(arrow)
  2558.             Bladex.AddScheduledFunc(Bladex.GetTime()+2.0, ThrownWeaponStopFunc,(arrow.Name,),"Stop Weapon: "+arrow.Name)
  2559.             arrow.Data.PrevInflictHitFunc= arrow.InflictHitFunc
  2560.             arrow.InflictHitFunc= ThrownWeaponInflictHitFunc
  2561.             arrow.Data.ThrownBy= me
  2562.  
  2563.             soltar_sound=Bladex.CreateEntity(arrow.Name+"FlySound", "Entity Sound", 0, 0, 0)
  2564.             soltar_sound.SetSound("..\\..\\Sounds\\ARCO-DISPARO-3.wav")
  2565.             soltar_sound.MinDistance=5000
  2566.             soltar_sound.MaxDistance=10000
  2567.             arrow.Link(soltar_sound)
  2568.             soltar_sound.PlaySound(0)
  2569.             #"ARCO-DISPARO-3.wav"
  2570.             #"M-CREAKCUERDA-44.wav"
  2571.  
  2572.             # Draw another arrow
  2573.             me.SetTmpAnmFlags(1,0,1,1,2,0)
  2574.             me.LaunchAnmType ("b2")
  2575.             return
  2576.     #print EntityName+" EndDrawBowEventHandler:b3"
  2577.     me.LaunchAnmType ("b3")
  2578.  
  2579.  
  2580. def CheckRefireBowEventHandler(EntityName, EventName):
  2581.     me= Bladex.GetEntity(EntityName)
  2582.     #print EntityName+" CheckRefireBowEventHandler, "+me.AnimName+": "+`me.AnmPos`
  2583.     if me.InvRight:
  2584.         action= BInput.GetInputManager().GetInputActions().Find("Attack")
  2585.         if action and action.this!="NULL" and action.CurrentlyActivated():
  2586.             me.Aim= 1
  2587.             me.Data.AimPressed= 1
  2588.  
  2589.         if me.Data.AimPressed:
  2590.             arrow= Bladex.GetEntity(me.InvRight)
  2591.             if arrow:
  2592.                 #print "CheckRefireBowEventHandler:Refire"
  2593.                 GraspString (EntityName,"GraspString")
  2594.                 me.DoActionWI ("b1", FixedFootAutoInterp, 0.3, 0.9)
  2595.                 tensar_sound=Bladex.CreateEntity(arrow.Name+"RedrawSound", "Entity Sound", 0, 0, 0)
  2596.                 tensar_sound.SetSound("..\\..\\Sounds\\M-CREAKCUERDA-44.wav")
  2597.                 tensar_sound.MinDistance=5000
  2598.                 tensar_sound.MaxDistance=10000
  2599.                 arrow.Link(tensar_sound)
  2600.                 tensar_sound.PlaySound(0)
  2601.                 return
  2602.         #else:
  2603.         #    print EntityName+" CheckRefireBowEventHandler, aimpressed: "+`me.Data.AimPressed`
  2604.         #    print EntityName+" CheckRefireBowEventHandler, InvRight: "+me.InvRight
  2605.         #print EntityName+" CheckRefireBowEventHandler:EndBowMode"
  2606.     EndBowMode(EntityName)
  2607.  
  2608. def EndReloadBowEventHandler(EntityName, EventName):
  2609.     #print EntityName+" In EndReloadBowEventHandler"
  2610.     me= Bladex.GetEntity(EntityName)
  2611.     if me.Aim:
  2612.         #print EntityName+" EndReloadBowEventHandler: b1"
  2613.         me.DoAction ("b1")
  2614.         #me.LaunchAnmType ("b1")
  2615.     else:
  2616.         # Default, go to rlx
  2617.         #print EntityName+" EndReloadBowEventHandler: Rlx_b"
  2618.         if not me.InvRight:
  2619.             TakeArrowEventHandler(EntityName, EventName)
  2620.         me.LaunchAnmType ("Rlx_b")
  2621.         #me.DoAction ("Rlx_b")
  2622.  
  2623.  
  2624. def FadeMeOut(EntityName,timer):
  2625.     if EntityName=="Player1":
  2626.         return
  2627.  
  2628.     me= Bladex.GetEntity(EntityName)
  2629.     current_alpha=me.Alpha
  2630.     if current_alpha>0.0:
  2631.         current_alpha=current_alpha-0.02
  2632.     else:
  2633.         me.Life=0
  2634.         me.RemoveFromList("Timer60")
  2635.  
  2636.     if current_alpha<0:
  2637.         current_alpha=0
  2638.  
  2639.     me.Alpha=current_alpha
  2640.     if me.InvRight:
  2641.         right=Bladex.GetEntity(me.InvRight)
  2642.         right.Alpha=current_alpha
  2643.     if me.InvLeft:
  2644.         left=Bladex.GetEntity(me.InvLeft)
  2645.         left.Alpha=current_alpha
  2646.     if me.InvRightBack:
  2647.         right2=Bladex.GetEntity(me.InvRightBack)
  2648.         right2.Alpha=current_alpha
  2649.     if me.InvLeftBack:
  2650.         left2=Bladex.GetEntity(me.InvLeftBack)
  2651.         left2.Alpha=current_alpha
  2652.  
  2653.  
  2654.  
  2655. def ClientCallBack(id,type,cad):
  2656.     if type==Netval.NET_GAME_FADE_DUE2BIGFALL:
  2657.         if netgame.GetClientId()==cad:
  2658.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL,END_FADEOUT_IN_BIG_FALL)
  2659.  
  2660. def ServerCallBack(id,type,cad):
  2661.     if type==Netval.NET_GAME_THROW_WEAPON:
  2662.         if netgame.GetNetState() == 1:
  2663.             params = string.split(cad)
  2664.             me = Bladex.GetEntity(params[0])
  2665.             coso = string.atof(params[1])
  2666.             if coso == -1:
  2667.                 TryDropRight(params[0])
  2668.             else:
  2669.                 me.Data.ThrowForce = coso
  2670.                 StdThrowObject(params[0])
  2671.  
  2672.  
  2673.  
  2674.  
  2675. def StartFadingOutPlayer(EntityName):
  2676.     me= Bladex.GetEntity(EntityName)
  2677.  
  2678.     net_state=netgame.GetNetState()
  2679.  
  2680.     if net_state==0:
  2681.         if EntityName=="Player1"and me.WillCrashInFloor==0:
  2682.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL,END_FADEOUT_IN_BIG_FALL)
  2683.     elif EntityName=="Player1":
  2684.         if me.WillCrashInFloor==0:
  2685.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL,END_FADEOUT_IN_BIG_FALL)
  2686.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL,EntityName)
  2687.     else:
  2688.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL,EntityName)
  2689.         me.TimerFunc=FadeMeOut
  2690.         me.SubscribeToList("Timer60")
  2691.  
  2692.  
  2693. def EndFadingOutPlayer(EntityName):
  2694.     me= Bladex.GetEntity(EntityName)
  2695.  
  2696.     me.Life=0
  2697.  
  2698.     net_state=netgame.GetNetState()
  2699.  
  2700.     me.Wuea=Reference.WUEA_ENDED
  2701.  
  2702.     if net_state==0: # NO red
  2703.         #me.LaunchAnmType("rlx")
  2704.         me.ImDeadFunc(me.Name)
  2705.         if EntityName=="Player1":
  2706.             if me.WillCrashInFloor==0:
  2707.                 int_pos=me.InitPos
  2708.                 me.Position=int_pos[0],int_pos[1],int_pos[2]
  2709.             else:
  2710.                 int_pos=me.InitPos
  2711.                 me.Position=int_pos[0],int_pos[1],int_pos[2]
  2712.  
  2713.     elif net_state==1: #Red -> Servidor
  2714.         me.Alpha=1.0
  2715.         Damage.PlayerHitFunc(me.Name,"BigFall", me.Life, 1)
  2716.     elif net_state==2: #Red -> Cliente
  2717.         me.Alpha=1.0
  2718.     else:
  2719.         print "Actions.py->EndFadingOutPlayer error . Unknown GetNetState()!!!"
  2720.  
  2721.  
  2722. def LinkNextAttack(EntityName, EventName):
  2723.     me= Bladex.GetEntity(EntityName)
  2724.  
  2725.     if me:
  2726.         me.RaiseEvent("HitFinalItpC")
  2727.  
  2728.     if not me.Data.NPC:
  2729.         Select.AutoSelectInAttack(EntityName)
  2730.  
  2731.  
  2732.  
  2733. def EndOfAttack(EntityName, EventName):
  2734.     me= Bladex.GetEntity(EntityName)
  2735.     if me:
  2736.         me.RaiseEvent("ActionEndC")
  2737.  
  2738.     if not me.Data.NPC:
  2739.         Select.AutoSelectInAttack(EntityName)
  2740.  
  2741. def BackUpEnemy(EntityName, EventName):
  2742.     me= Bladex.GetEntity(EntityName)
  2743.     me.Data.TmpEnemy=me.ActiveEnemy
  2744.  
  2745.  
  2746. def Swap180Handler(EntityName, EventName):
  2747.     me= Bladex.GetEntity(EntityName)
  2748.  
  2749.     if me.Data and me.Data.TmpEnemy and me.Data.TmpEnemy==me.ActiveEnemy:
  2750.         me.SetActiveEnemy(None)
  2751.  
  2752.         #Quitada la sigu comprobacion
  2753.         if me.Data.selected_enemy:
  2754.             ene=Bladex.GetEntity(me.Data.selected_enemy[0])
  2755.             if me and ene.Person:
  2756.                 me.SetActiveEnemy(ene)
  2757.     else:
  2758.         if me.Data.selected_enemy:
  2759.             ene=Bladex.GetEntity(me.Data.selected_enemy[0])
  2760.             if me and ene.Person:
  2761.                 me.SetActiveEnemy(ene)
  2762.  
  2763.  
  2764.  
  2765. def EndTransitionFllHugeHandler(EntityName, EventName):
  2766.     me= Bladex.GetEntity(EntityName)
  2767.  
  2768.     #enemigos?
  2769.  
  2770.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.2, StartFadingOutPlayer,(EntityName,),"StartFadingOutPlayer "+EntityName)
  2771.     me.AnmEndedFunc=TakeMainAnm=EndFadingOutPlayer
  2772.     #Puesto en AnmEnd en lugar de Scheduled...
  2773.     #Bladex.AddScheduledFunc(Bladex.GetTime()+1.0, EndFadingOutPlayer,(EntityName,),"EndFadingOutPlayer "+EntityName)
  2774.  
  2775. def W2hToLeftHandler(EntityName, EventName):
  2776.     me= Bladex.GetEntity(EntityName)
  2777.     ObjectName=me.InvRight
  2778.     if ObjectName=="None" or not ObjectName:
  2779.         print "W2hToLeftHandle-> Event in a unexpected situation!!! Entity " + EntityName + " in animation " +me.AnimName
  2780.         return
  2781.  
  2782.     inv=me.GetInventory()
  2783.     inv.LinkRightHand("None")
  2784.  
  2785.     object=Bladex.GetEntity(ObjectName)
  2786.     node= me.GetNodeIndex("L_Hand")
  2787.     me.LinkToNode(object,node)
  2788.     me.Data.TmpW2h=ObjectName
  2789.  
  2790.  
  2791. def W2hToRightHandler(EntityName, EventName):
  2792.     me= Bladex.GetEntity(EntityName)
  2793.  
  2794.     if not("TmpW2h" in dir(me.Data)):
  2795.         me.Data.TmpW2h=""
  2796.         return
  2797.  
  2798.     if me.Data.TmpW2h == None:
  2799.         return
  2800.  
  2801.     if me.Data.TmpW2h=="":
  2802.         return
  2803.  
  2804.     inv=me.GetInventory()
  2805.     object=Bladex.GetEntity(me.Data.TmpW2h)
  2806.     me.Unlink(object)
  2807.     inv.LinkLeftHand("None")
  2808.     inv.LinkRightHand(me.Data.TmpW2h)
  2809.     me.Data.TmpW2h=""
  2810.  
  2811. # simple take used for network bindings
  2812. def AutoTake(EntityName):
  2813.     me = Bladex.GetEntity(EntityName)
  2814.     if me.InvRight:
  2815.         if not FreeBothHands(EntityName,None,(),0):
  2816.             return
  2817.  
  2818.     head_pos=me.Rel2AbsPoint(0.0,0.0,0.0)
  2819.     pj_dir=me.Rel2AbsVector(0.0,-1.0,0.0)
  2820.     list=Bladex.GetObjectEntitiesVisibleFrom(head_pos,5000.0,pj_dir,0.0)
  2821.     for n in list:
  2822.         o = Bladex.GetEntity(n)
  2823.         if (o.Parent == None) | (o.Parent == ""):
  2824.             if IsValidForTaking(n) & o.Weapon :
  2825.                 if TryToTake(EntityName,n):
  2826.                     return 1
  2827.  
  2828. ##################################################################################################
  2829. ##########################################  INSTANT ATTACK  ##########################################
  2830. ##################################################################################################
  2831.  
  2832.  
  2833.  
  2834. def ToggleIAttackRight(EntityName,event):
  2835.     me = Bladex.GetEntity(EntityName)
  2836.     if not me.InvRightBack or me.InvRightBack=="":
  2837.         print "Error in Actions.ToggleIAttackRight"
  2838.         return
  2839.  
  2840.     inv= me.GetInventory()
  2841.  
  2842.     tmpr_back=me.InvRightBack
  2843.  
  2844.     inv.LinkRightBack("None")
  2845.     inv.LinkRightHand(tmpr_back)
  2846.  
  2847.     if not me.InCombat:
  2848.         import DefaultSelectionData
  2849.         DefaultSelectionData.SelectEnemy()
  2850.  
  2851.  
  2852. def ToggleIAttackLeft(EntityName,event):
  2853.     me = Bladex.GetEntity(EntityName)
  2854.     if not me.InvLeftBack or me.InvLeftBack=="":
  2855.         return
  2856.  
  2857.     inv= me.GetInventory()
  2858.  
  2859.     tmpl_back=me.InvLeftBack
  2860.     inv.LinkLeftBack("None")
  2861.     inv.LinkLeftHand(tmpl_back)
  2862.  
  2863.  
  2864. def InstantAttackSlow(EntityName, EventName):
  2865.     me = Bladex.GetEntity(EntityName)
  2866.     if (not me.Data.NPC) and me.GotAnmType("g_draw_rlx"):
  2867.         me.AddAnmEventFunc("ChangeREvent",ToggleIAttackRight)
  2868.         me.AddAnmEventFunc("ChangeLEvent",ToggleIAttackLeft)
  2869.         me.AttackFunc (EntityName, "g_draw_rlx")
  2870.     elif not me.Data.NPC:
  2871.         print "No instant attack for not having the animation!! ----3D Dept---" + EntityName
  2872.  
  2873.  
  2874. def InstantAttackRun(EntityName, EventName):
  2875.     me = Bladex.GetEntity(EntityName)
  2876.     if me.GotAnmType("g_draw_run"):
  2877.         me.AddAnmEventFunc("ChangeREvent",ToggleIAttackRight)
  2878.         me.AddAnmEventFunc("ChangeLEvent",ToggleIAttackLeft)
  2879.         me.AttackFunc (EntityName, "g_draw_run")
  2880.     else:
  2881.         if me.Data.NPC==0:
  2882.             print "No instant attack for not having the animation!! ----3D Dept---" + EntityName
  2883.  
  2884.  
  2885.  
  2886. def LinkContinuosSoundAux(csound):
  2887.     csound.PlaySound(-1)
  2888.  
  2889.  
  2890.  
  2891. def LinkContinuosSound(EntityName,SoundName,max_dist=12000,min_dist=5000):
  2892.     me = Bladex.GetEntity(EntityName)
  2893.     csound=Bladex.CreateEntity(EntityName+"ContinuosSound", "Entity Sound", 0,0,0)
  2894.     csound.SetSound(SoundName)
  2895.     csound.MinDistance=min_dist
  2896.     csound.MaxDistance=max_dist
  2897.     me.Link(csound)
  2898.     #Otherwise it would not work (the SS does NOT launch any sounds when loading!!!)
  2899.     Bladex.AddScheduledFunc(Bladex.GetTime()+1.0,LinkContinuosSoundAux,(csound,),"LinkContinuosSoundAux")
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907. ##################################################################################################
  2908. ##########################################  FIRE DEATH  ##########################################
  2909. ##################################################################################################
  2910.  
  2911. def CicloDeluz(PersonName,val):
  2912.     per = Bladex.GetEntity(PersonName)
  2913.     if per:
  2914.         if   val < 1.0:
  2915.             per.SelfIlum = val
  2916.             Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, CicloDeluz,(PersonName,val+0.1))
  2917.             wps=Bladex.GetEntity(PersonName+"WPS")
  2918.             if wps:
  2919.                 wps.PPS=wps.PPS+25
  2920.         elif val < 2.0:
  2921.             per.Alpha = -val+1.9
  2922.             Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, CicloDeluz,(PersonName,val+0.1))
  2923.  
  2924. def HumoDeFuego(PersonName):
  2925.     per = Bladex.GetEntity(PersonName)
  2926.     if per:
  2927.         wps=Bladex.CreateEntity(PersonName+"WPSmk", "Entity Particle System Dperson", 0.0, 0.0, 0.0)
  2928.         wps.PersonName=PersonName
  2929.         wps.ParticleType="DarkSmoke"
  2930.         wps.Time2Live=96
  2931.         wps.RandomVelocity=0
  2932.         wps.Velocity=0,0,0
  2933.         wps.NormalVelocity=5
  2934.         wps.YGravity=0
  2935.         wps.PPS=125
  2936.         wps.DeathTime=Bladex.GetTime()+1.0
  2937.  
  2938. def FreezeMeGuy(PersonName):
  2939.     import GameText
  2940.     per = Bladex.GetEntity(PersonName)
  2941.     per.Freeze()
  2942.     per.RemoveFromWorld()
  2943.     if (netgame.GetNetState()==0) and (Reference.DEMO_MODE==0) and (PersonName=="Player1") and GameText.MapList.has_key(string.upper(Bladex.GetCurrentMap())):
  2944.         import SaveGame        
  2945.         Bladex.AddScheduledFunc(Bladex.GetTime()+7.0,SaveGame.MenuStart,(PersonName,))
  2946.  
  2947. def RePutTheFuckingEndFunction(PersonName):
  2948.     per = Bladex.GetEntity(PersonName)
  2949.     per.AnmEndedFunc = FreezeMeGuy
  2950.  
  2951.  
  2952. def FireDeath(PersonName = "Player1",ParType="LargeFire",NumPart=32):
  2953.     TIME_TO_FIRE = 12.0
  2954.     per = Bladex.GetEntity(PersonName)
  2955.     if per:
  2956.         wps=Bladex.CreateEntity(PersonName+"WPS", "Entity Particle System Dperson", 0.0, 0.0, 0.0)
  2957.         wps.PersonName=PersonName
  2958.         wps.ParticleType=ParType
  2959.         wps.Time2Live=NumPart
  2960.         wps.RandomVelocity=1.0
  2961.         wps.Velocity=0,-300,0
  2962.         wps.NormalVelocity=3
  2963.         wps.YGravity=0
  2964.         wps.PPS=200
  2965.         wps.DeathTime=Bladex.GetTime()+TIME_TO_FIRE
  2966.         Bladex.AddScheduledFunc(Bladex.GetTime()+TIME_TO_FIRE-0,  HumoDeFuego, (PersonName,))
  2967.         if netgame.GetNetState()!=2:
  2968.             per.SelfIlum = 0.0
  2969.             per.Alpha    = 1.0
  2970.             Bladex.AddScheduledFunc(Bladex.GetTime()+TIME_TO_FIRE-2,   CicloDeluz,  (PersonName,0))
  2971.             Bladex.AddScheduledFunc(Bladex.GetTime()+1.5,RePutTheFuckingEndFunction,(PersonName,))
  2972.             per.LaunchAnmType("dth_burn")
  2973.             per.AnmEndedFunc = FreezeMeGuy
  2974.             if per.Name == "Player1":
  2975.                 cam  = Bladex.GetEntity("Camera")
  2976.                 cam.SType = 0
  2977.                 cam.TType = 0
  2978.  
  2979. def ToggleInvincibility():
  2980.     me= Bladex.GetEntity("Player1")
  2981.     try:
  2982.         if me:
  2983.             if not me.Data.Invincibility:
  2984.                 import pocimac
  2985.                 me.Life= CharStats.GetCharMaxLife(me.Kind,me.Level)
  2986.                 pocimac.RestoreWoundsToLifeLevel(me.Name)
  2987.                 me.Data.Invincibility= TRUE
  2988.                 ReportMsg ("Enabling INVINCIBILITY mode")
  2989.             else:
  2990.                 me.Data.Invincibility= FALSE
  2991.                 ReportMsg ("Disabling INVINCIBILITY mode")
  2992.     except AttributeError: pass
  2993.  
  2994. profiler_on=1
  2995. def ToggleProfiling():
  2996.     global profiler_on
  2997.     profiler_on= not profiler_on
  2998.     if not profiler_on:
  2999.         print "Switching off Profiler"
  3000.         Bladex.SetCallCheck(3)
  3001.         Bladex.SaveProfileData("Profile.txt")
  3002.         Bladex.StartProfile()
  3003.         Bladex.DisableProfiler()
  3004.     else:
  3005.         print "Switching on Profiler"
  3006.         Bladex.SetCallCheck(11)
  3007.         Bladex.EnableProfiler()
  3008.         Bladex.StartProfile()
  3009.  
  3010. def QuickDeath(EntityName,EventName):
  3011.     Bladex.GetEntity(EntityName).Life = 0
  3012.     if EntityName == "Player1":
  3013.         import SaveGame        
  3014.         Bladex.AddScheduledFunc(Bladex.GetTime()+5.0,SaveGame.MenuStart,(EntityName,))
  3015.         AuxFuncs.FadeTo(3.5,10.0,128,0,0)
  3016.  
  3017. ##################################################################################################